from machine import Pin,I2C
import ssd1306,time
i2c = I2C(0, scl=Pin(12), sda=Pin(32))
oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)
led_b = Pin(23, Pin.OUT)
led_j = Pin(19, Pin.OUT)
led_r = Pin(4, Pin.OUT)
led_v = Pin(22, Pin.OUT)
button_b = Pin(21, Pin.IN, Pin.PULL_UP)
button_j = Pin(18, Pin.IN, Pin.PULL_UP)
button_r = Pin(5, Pin.IN, Pin.PULL_UP)
button_v = Pin(2, Pin.IN, Pin.PULL_UP)
score = 0
while True:
i = 0
# Ajouter une nouvelle valeur aléatoire dans la séquence simon
coul ["b""j""r""v"]
coul(random(sequence_simon))
# Afficher les LEDS de la séquence simon une par une
for coul in sequence_simon:
if coul == "b":
led_b.on()
elif coul == "j":
led_j.on()
elif coul == "r":
led_r.on()
elif coul == "v":
led_v.on()
# Attendre que l'utilisateur appui sur les boutons
# Pour chaque bouton appuyé, vérifier si c'est le bon.
if led_b.value() == 1 and button_b.value() == 0:
score += 1
elif led_b.value() == 0 and button_b.value() == 1:
score +=0
if led_j.value() ==1 and button_j.value() == 0:
score+=1
elif led_j.value() == 0 and button_j.value() ==1:
score +=0
if led_r.value() ==1 and button_r.value() == 0:
score +=1
elif led_r.value() == 0 and button_r.value() ==1:
score +=0
if led_v.value() ==1 and button_v.value() == 0:
score +=1
elif led_v.value() == 0 and button_v.value() ==1:
score +=0
maxi = 4
for _ in range (0,maxi):
nb_choisi=random.randint(0,3)
if nb_choisi == 0:
led_b.on()
elif nb_choisi == 1:
led_j.value() == 1
elif nb_choisi == 2:
led_r.value() == 1
elif nb_chosi == 3:
led_v.value() == 1