from machine import Pin, SoftI2C
import ssd1306
from time import sleep_ms
A1 = Pin(32, mode=Pin.IN, pull=Pin.PULL_UP)
B1 = Pin(33, mode=Pin.IN, pull=Pin.PULL_UP)
A2 = Pin(25, mode=Pin.IN, pull=Pin.PULL_UP)
B2 = Pin(26, mode=Pin.IN, pull=Pin.PULL_UP)
busi2c = SoftI2C(scl=Pin(22), sda=Pin(21))
oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, busi2c)
def afficher(texte):
oled.fill(0)
oled.text(texte, 0, 10,1)
#sleep_ms(500)
oled.show()
def raz():
global valeurA1, valeurA2
global valeurB1, valeurB2
global joueur1, joueur2
valeurA1 = False
valeurB1 = False
valeurA2 = False
valeurB2 = False
joueur1 = False
joueur2 = False
raz()
victoire = 0
echec = 0
while True:
print(A1.value())
print(B1.value())
print(A2.value())
print(B2.value())
if A1.value() == 0:
valeurA1 = True
joueur1 = not joueur1
if B1.value() == 0:
valeurB1 = True
joueur1 = not joueur1
if A2.value() == 0:
valeurA2 = True
joueur2 = not joueur2
if B2.value() == 0:
valeurB2 = True
joueur2 = not joueur2
print(f'valeurA1:{valeurA1}, joueur1:{joueur1}')
print(f'valeurB1:{valeurB1}, joueur1:{joueur1}')
print(f'valeurA2:{valeurA2}, joueur2:{joueur2}')
print(f'valeurB2:{valeurB2}, joueur2:{joueur2}')
if joueur1 ^ joueur2:
afficher('A vous de jouer')
sleep_ms(1000)
elif joueur1 & joueur2:
if (valeurA1 & valeurA2) | (valeurB1 & valeurB2):
afficher('Bravo')
sleep_ms(1000)
victoire += 1
else:
echec += 1
raz()
else:
try:
taux_reussite = round(100*victoire/(victoire+echec),1)
message = 'Taux : '+ str(taux_reussite)+'%'
except ZeroDivisionError:
message = 'en attente'
afficher(message)
sleep_ms(1000)