2022-11-04 16:30:35 +01:00
|
|
|
from microbit import uart, sleep
|
|
|
|
from microbit import *
|
|
|
|
|
|
|
|
###############################################################################
|
2022-11-06 14:49:34 +01:00
|
|
|
# microbit-serialreader.py
|
2022-11-04 16:30:35 +01:00
|
|
|
# @title: Lecteur du port serie d'une carte micro:bit
|
|
|
|
# @project: Ropy (Blender-EduTech)
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
uart.init(baudrate= 115200) # Initialisation du port série
|
|
|
|
|
|
|
|
while True:
|
|
|
|
|
|
|
|
while not uart.any(): # Attente d'un message
|
2022-11-06 14:49:34 +01:00
|
|
|
|
|
|
|
# Envoi d'un message
|
|
|
|
if button_a.is_pressed() :
|
|
|
|
display.scroll("-> A")
|
2022-11-07 03:09:51 +01:00
|
|
|
uart.write("A\n")
|
2022-11-06 14:49:34 +01:00
|
|
|
if button_b.is_pressed() :
|
|
|
|
display.scroll("-> B")
|
2022-11-07 03:09:51 +01:00
|
|
|
uart.write("B\n")
|
2022-11-06 14:49:34 +01:00
|
|
|
# pass
|
|
|
|
|
|
|
|
# Réception d'un message
|
2022-11-05 02:20:39 +01:00
|
|
|
msg = uart.readline()
|
|
|
|
display.scroll(msg[:-1]) # Affichage du message sans le '/n'
|
2022-11-07 03:09:51 +01:00
|
|
|
# display.scroll(str(msg[0])+" "+str(msg[1])) # Affichage du message en code ASCII
|
2022-11-04 16:30:35 +01:00
|
|
|
sleep(400)
|