#from mfrc522 import MFRC522
from machine import Pin, I2C
import ssd1306
import utime
#Configuration RFID
#reader = MFRC522(spi_id=0,sck=2,miso=4,mosi=3,cs=1,rst=0)
tagid = 1399450055
cartid = 1041993789
wrongid = 11111111
list_cards = [tagid, cartid]
list_loop_button = [tagid, cartid, wrongid]
#Configuration push button (pull down)
bouton= Pin(16, Pin.IN, Pin.PULL_DOWN)
#configuration du I2C
i2c = I2C(0, sda=Pin(8), scl=Pin(9))
display = ssd1306.SSD1306_I2C(128, 64, i2c) # create SSD1306 object
#Configuration de RGB
red = Pin(13, Pin.OUT)
green = Pin(12, Pin.OUT)
blue = Pin(11, Pin.OUT)
print("Bring TAG closer...")
print("")
memento = bouton.value()
id = 0
while 1:
#BASCULEMENT ENTRE ETATS
if bouton.value() and bouton.value() != memento:
if not id:
id = list_loop_button[0]
elif id == list_loop_button[0]:
id = list_loop_button[1]
elif id == list_loop_button[1]:
id = list_loop_button[2]
elif id == list_loop_button[2]:
id = list_loop_button[0]
memento = bouton.value()
#Message affiché sur l'OLED et alimentation LED
display.fill(0)
if id == 0:
display.text("Bring TAG closer...", 0, 10)
elif id == list_loop_button[0]:
display.text("ID :"+str(id), 0, 10)
display.text("Access granted !", 0, 20)
green.high()
red.low()
blue.low()
elif id == list_loop_button[1]:
display.text("ID :"+str(id), 0, 10)
display.text("Access granted !", 0, 20)
green.high()
red.high()
blue.low()
elif id == list_loop_button[2]:
display.text("ID :"+str(id), 0, 10)
display.text("Access denied.", 0, 20)
red.high()
blue.low()
green.low()
display.show()
utime.sleep(0.02)