from time import sleep
import machine
from machine import Pin, I2C
import time
import ssd1306
# Initialisation I2C (ESP32)
i2c = I2C(0, scl=Pin(23), sda=Pin(21))
# Initialisation OLED 128x64
oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)
#ledVerte = Pin(19, Pin.OUT)
ledRouge = Pin(32, Pin.OUT)
boutton= Pin(26,Pin.IN, Pin.PULL_UP)
#bouton= Pin(27,machine.Pin.IN,machine.Pin.PULL_UP)
print('code activé')
while True:
state = boutton.value()
if not state:
ledRouge.on()
oled.fill(0)
oled.text('led alluméé')
time.sleep(0.5)
ledRouge.off()
oled.fill(0)
time.sleep(0.5)
else:
# On réduit le sleep ici pour plus de réactivité
time.sleep(0.1)