from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
from mfrc522 import MFRC522
import utime
reader = MFRC522(spi_id=0,sck=2,miso=4,mosi=3,cs=1,rst=0)
# Configuration de l'afficheur OLED I2C
i2c = I2C(0, scl=Pin(9), sda=Pin(8), freq=400000)
oled = SSD1306_I2C(128, 64, i2c)
red = Pin(13, Pin.OUT)
green = Pin(12, Pin.OUT)
blue = Pin(11, Pin.OUT)
print("Bring RFID TAG Closer...")
##display_text("approche rfid", x=10, y=10)
while True:
reader.init()
(stat, tag_type) = reader.request(reader.REQIDL)
if stat == reader.OK:
(stat, uid) = reader.SelectTagSN()
print("OK1")
red.value(0)
green.value(0)
blue.value(1)
if stat == reader.OK:
card = int.from_bytes(bytes(uid),"little",False)
print("OK2")
if card == 1980835637:
print("Card ID: "+ str(card)+" PASS: Green Light Activated")
red.value(0)
green.value(1)
blue.value(0)
print("OK3")
oled.fill(0)
oled.text("carte valide", 0, 0)
oled.text("ID:", 0, 36)
oled.text(""+ str(card)+"", 22, 36)
oled.show()
elif card == 45557151:
print("Card ID: "+ str(card)+" PASS: Blue Light Activated")
red.value(0)
green.value(1)
blue.value(0)
print("OK4")
oled.fill(0)
oled.text("carte valide", 0, 0)
oled.text("ID:", 0, 36)
oled.text(""+ str(card)+"", 22, 36)
oled.show()
else:
print("Card ID: "+ str(card)+" UNKNOWN CARD! Red Light Activated")
red.value(1)
green.value(0)
blue.value(0)
print("OK5")
oled.fill(0)
oled.text("carte invalide", 0, 0)
oled.text("ID:", 0, 36)
oled.text(""+ str(card)+"", 22, 36)
oled.show()
utime.sleep_ms(500)