zoukankan      html  css  js  c++  java
  • MFRC522控制LED

    既然已经读取卡片的ID,那么就简单实现一个RFID门卡控制LED试试。

    import RPi.GPIO as GPIO
    import mfrc522
    import signal
    import time
    
    GPIO.setmode(GPIO.BCM)
    continue_reading = True
     
    # Capture SIGINT for cleanup when the script is aborted
    def end_read(signal,frame):
        global continue_reading
        print ("Ctrl+C captured, ending read.")
        continue_reading = False
        GPIO.cleanup()
     
    # Hook the SIGINT
    signal.signal(signal.SIGINT, end_read)
     
    # Create an object of the class MFRC522
    MIFAREReader = mfrc522.MFRC522()
     
    # Welcome message
    print ("Welcome to the MFRC522 data read example")
    print ("Press Ctrl-C to stop.")
     
    # This loop keeps checking for chips. If one is near it will get the UID and authenticate
    while continue_reading:
        
        # Scan for cards    
        (status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)
     
        # If a card is found
        if status == MIFAREReader.MI_OK:
            print ("Card detected")
        
        # Get the UID of the card
        (status,uid) = MIFAREReader.MFRC522_Anticoll()
     
        # If we have the UID, continue
        if status == MIFAREReader.MI_OK:
     
            # Print UID
            print ("Card read UID: "+str(uid[0])+","+str(uid[1])+","+str(uid[2])+","+str(uid[3])+','+str(uid[4]))  
            # This is the default key for authentication
            key = [0xFF,0xFF,0xFF,0xFF,0xFF,0xFF]
            
            # Select the scanned tag
            MIFAREReader.MFRC522_SelectTag(uid)
            
            #ENTER Your Card UID here
            my_uid = [213,179,104,28,18]
            
            #Configure LED Output Pin
            LED = 18
            GPIO.setup(LED, GPIO.OUT)
            GPIO.output(LED, GPIO.LOW)
            
            #Check to see if card UID read matches your card UID
            if uid == my_uid:                #Open the Doggy Door if matching UIDs
                print("Access Granted")
                GPIO.output(LED, GPIO.HIGH)  #Turn on LED
                time.sleep(5)                #Wait 5 Seconds
                GPIO.output(LED, GPIO.LOW)   #Turn off LED
                
            else:                            #Don't open if UIDs don't match
                print("Access Denied, YOU SHALL NOT PASS!")
    

    MFRC522读卡器接完之后,在GPIO18上接一个LED灯即可。有想法的话把LED换成门锁就是门禁系统了。

  • 相关阅读:
    QT5.4 vs2013静态加载插件的sqlite静态编译
    四个漂亮的CSS样式表
    程序猿写的程序将如何打包成安装包(最简单)
    cocos2d的-X- luaproject的LUA脚本加密
    【【分享】深入浅出WPF全系列教程及源码 】
    C#的StringBuilder 以及string字符串拼接的效率对照
    【Android中Broadcast Receiver组件具体解释 】
    【蜗牛—漫漫IT路之大学篇(九) 】
    【分布式存储系统sheepdog 】
    C#异步调用
  • 原文地址:https://www.cnblogs.com/1328497946TS/p/12026514.html
Copyright © 2011-2022 走看看