import machine
import utime
from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
# Configuration des broches
B_P1= 14 # Broche du premier bouton
B_P2 = 15 # Broche du deuxième bouton
RED_PIN = 20 # Broche de la LED rouge
GREEN_PIN = 19 # Broche de la LED verte
BLUE_PIN = 18 # Broche de la LED bleue
# Initialisation des broches
Bouton_1 = Pin(B_P1, Pin.IN, Pin.PULL_UP)
Bouton_2 = Pin(B_P2, Pin.IN, Pin.PULL_UP)
led_red = Pin(RED_PIN, Pin.OUT)
led_green = Pin(GREEN_PIN, Pin.OUT)
led_blue = Pin(BLUE_PIN, Pin.OUT)
# Configuration de l'écran OLED
i2c = I2C(0, scl=Pin(9), sda=Pin(8), freq=400000)
oled = SSD1306_I2C(128, 64, i2c)
# Boucle principale
while True:
if not Bouton_1.value():
# Bouton 1 pressé
led_red.on() # LED rouge ON
led_green.off() # LED verte OFF
led_blue.off() # LED bleue OFF
oled.fill(0) # RESET OLED
oled.text("RFID inconnu", 0, 0)
oled.show()
utime.sleep(2)
elif not Bouton_2.value():
# Bouton 2 pressé
led_red.off() # LED rouge OFF
led_green.on() # LED verte ON
led_blue.off() # LED bleue OFF
oled.fill(0) # RESET OLED
oled.text("RFID autorise", 0, 0)
oled.show()
utime.sleep(2)
else:
# Aucun bouton pressé
led_red.off() # LED rouge OFF
led_green.off() # LED verte OFF
led_blue.on() # LED bleue ON
oled.fill(0) # OLED RESET
oled.text("Scanner votre", 0, 0)
oled.text("badge RFID", 0, 16)
oled.show()
utime.sleep(0.1) #Evite les bugs