Tutoriels 5 : programmes ok

This commit is contained in:
Philippe Roy 2023-05-17 15:51:34 +02:00
parent a643bf86f4
commit a8d8134d64
2 changed files with 14 additions and 14 deletions

View File

@ -121,6 +121,7 @@ void loop() {
// Victoire
if (xy==92) matrix.writeOnePicture(0x003c428100666600);
// Affichage
matrix.display();
serial_msg = "";
serial_msg_complet = false;

View File

@ -18,7 +18,7 @@ from microbit import *
# Initialisation
###############################################################################
attente_image = Image("00000:00000:00900:00000:00000")
attente_image = Image("00000:00000:00300:00000:00000")
display.show(attente_image) # Témoin de fonctionnement
uart.init(baudrate= 115200) # Initialisation du port série
@ -31,29 +31,28 @@ msg_str=''
while True:
# A propos
if button_a.is_pressed() or button_b.is_pressed():
display.scroll("Labyrinte")
display.show(attente_image) # Témoin de fonctionnement
# Inclinaison de la carte -> UBGE
accel_x=accelerometer.get_x() # Roulis
accel_y=accelerometer.get_y() # Tangage
uart.write(str(accel_x)+","+str(accel_y)+"\n")
# UBGE -> micro:bit (lecture du message)
new_byte = (uart.read(1))
if new_byte == None:
continue
new_char = str(new_byte, 'ascii')
msg_str += new_char
# Affichage de la position de la bille
if ("\n" in msg_str):
msg_byte = uart.readline()
if msg_byte:
display.clear()
msg_str = str(msg_byte, 'ascii')
if "91" in msg_str: # Chute
display.show(Image.ANGRY)
display.show(Image.SAD)
sleep(500);
uart.write("start\n")
elif "92" in msg_str: # Victoire
display.show(Image.HAPPY)
uart.write("start\n")
else: # Position de la bille
display.set_pixel(int(msg_str[0]), int(msg_str[1]), 9)
msg_str = ''
sleep(100)