2022-11-04 16:30:35 +01:00
|
|
|
from microbit import uart, sleep
|
|
|
|
from microbit import *
|
2022-11-04 19:37:55 +01:00
|
|
|
import radio
|
2022-11-04 16:30:35 +01:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# rp_twins_maqueen-relay.py
|
2022-11-06 14:49:34 +01:00
|
|
|
# @title: Jumeau Maqueen : Programme de la carte microbit du relais
|
2022-11-04 16:30:35 +01:00
|
|
|
# @project: Ropy (Blender-EduTech)
|
|
|
|
# @lang: fr
|
|
|
|
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
|
|
|
|
# @copyright: Copyright (C) 2022 Philippe Roy
|
|
|
|
# @license: GNU GPL
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# Initialisation
|
|
|
|
###############################################################################
|
|
|
|
|
2022-11-05 02:20:39 +01:00
|
|
|
attente_image = Image("00000:00000:00300:00000:00000")
|
2022-11-04 19:37:55 +01:00
|
|
|
display.show(attente_image) # Témoin de fonctionnement
|
2022-11-06 14:49:34 +01:00
|
|
|
balise_image = Image("33333:36663:36963:36663:33333")
|
2022-11-05 05:08:39 +01:00
|
|
|
radio.config(group=1, queue=4, length=8)
|
2022-11-04 16:30:35 +01:00
|
|
|
radio.on()
|
|
|
|
|
|
|
|
uart.init(baudrate= 115200) # Initialisation du port série
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# Écoute du port série en relayage vers la radio
|
|
|
|
###############################################################################
|
|
|
|
|
2022-11-06 14:49:34 +01:00
|
|
|
temps_avancer=10
|
|
|
|
temps_tourner=10
|
|
|
|
temps_marquer=100
|
|
|
|
temps_objectif=100
|
|
|
|
temps_forer=100
|
|
|
|
temps_colision=100
|
2022-11-04 16:30:35 +01:00
|
|
|
|
2022-11-05 02:20:39 +01:00
|
|
|
while True:
|
2022-11-06 14:49:34 +01:00
|
|
|
|
2022-11-04 16:30:35 +01:00
|
|
|
while not uart.any(): # Attente d'un message
|
2022-11-06 14:49:34 +01:00
|
|
|
|
|
|
|
if button_a.is_pressed() or button_b.is_pressed(): # A propos
|
|
|
|
display.scroll ("Ropy : Relais")
|
|
|
|
display.show(attente_image) # Témoin de fonctionnement
|
|
|
|
# pass
|
2022-11-04 19:37:55 +01:00
|
|
|
|
2022-11-05 02:20:39 +01:00
|
|
|
display.show(' ') # Sinon bug ?
|
2022-11-04 19:37:55 +01:00
|
|
|
msg = uart.readline()
|
2022-11-06 14:49:34 +01:00
|
|
|
|
2022-11-04 19:37:55 +01:00
|
|
|
# Avancer : AV
|
2022-11-05 02:20:39 +01:00
|
|
|
if msg[0] ==65 and msg[1] ==86 : # Code ASCII : 65 (A) puis 86 (V)
|
2022-11-04 19:37:55 +01:00
|
|
|
display.show(Image.ARROW_N)
|
2022-11-05 02:20:39 +01:00
|
|
|
radio.send("AV")
|
|
|
|
sleep(temps_avancer)
|
2022-11-04 19:37:55 +01:00
|
|
|
|
|
|
|
# Reculer : RE
|
2022-11-05 02:20:39 +01:00
|
|
|
if msg[0] ==82 and msg[1] ==69 : # Code ASCII : 82 (R) puis 69 (E)
|
2022-11-04 19:37:55 +01:00
|
|
|
display.show(Image.ARROW_S)
|
2022-11-05 02:20:39 +01:00
|
|
|
radio.send("RE")
|
|
|
|
sleep(temps_avancer)
|
2022-11-04 19:37:55 +01:00
|
|
|
|
|
|
|
# Gauche : GA
|
2022-11-05 02:20:39 +01:00
|
|
|
if msg[0] ==71 and msg[1] ==65 : # Code ASCII : 71 (G) puis 65 (A)
|
2022-11-04 19:37:55 +01:00
|
|
|
display.show(Image.ARROW_W)
|
2022-11-05 02:20:39 +01:00
|
|
|
radio.send("GA")
|
|
|
|
sleep(temps_tourner)
|
2022-11-04 19:37:55 +01:00
|
|
|
|
|
|
|
# Droite : DR
|
2022-11-06 14:49:34 +01:00
|
|
|
if msg[0] ==68 and msg[1] ==82 : # Code ASCII : 68 (D) puis 82 (R)
|
2022-11-04 19:37:55 +01:00
|
|
|
display.show(Image.ARROW_E)
|
2022-11-05 02:20:39 +01:00
|
|
|
radio.send("DR")
|
|
|
|
sleep(temps_tourner)
|
2022-11-04 19:37:55 +01:00
|
|
|
|
|
|
|
# Marquer : MA
|
2022-11-05 02:20:39 +01:00
|
|
|
if msg[0] ==77 and msg[1] ==65 : # Code ASCII : 77 (M) puis 65 (A)
|
2022-11-04 19:37:55 +01:00
|
|
|
display.show(balise_image)
|
2022-11-06 14:49:34 +01:00
|
|
|
radio.send("MA")
|
2022-11-05 02:20:39 +01:00
|
|
|
sleep(temps_marquer)
|
2022-11-04 19:37:55 +01:00
|
|
|
|
2022-11-06 14:49:34 +01:00
|
|
|
# Objectif atteint : OB
|
|
|
|
if msg[0] ==79 and msg[1] ==66 : # Code ASCII : 79 (O) puis 66 (B)
|
|
|
|
display.show(Image.HAPPY)
|
|
|
|
radio.send("OB")
|
|
|
|
sleep(temps_objectif)
|
|
|
|
display.show(attente_image) # Témoin de fonctionnement
|
|
|
|
|
2022-11-04 19:37:55 +01:00
|
|
|
# Forer : FO
|
2022-11-05 02:20:39 +01:00
|
|
|
if msg[0] ==70 and msg[1] ==79 : # Code ASCII : 70 (F) puis 79 (O)
|
2022-11-04 19:37:55 +01:00
|
|
|
display.show(Image.DIAMOND)
|
2022-11-06 14:49:34 +01:00
|
|
|
radio.send("FO")
|
2022-11-05 02:20:39 +01:00
|
|
|
sleep(temps_forer)
|
2022-11-04 19:37:55 +01:00
|
|
|
|
|
|
|
# Colision : CO
|
2022-11-05 02:20:39 +01:00
|
|
|
if msg[0] ==67 and msg[1] ==79 : # Code ASCII : 67 (C) puis 79 (O)
|
2022-11-04 19:37:55 +01:00
|
|
|
display.show(Image.SKULL)
|
2022-11-06 14:49:34 +01:00
|
|
|
radio.send("CO")
|
2022-11-05 02:20:39 +01:00
|
|
|
sleep(temps_colision)
|
|
|
|
|
|
|
|
# Configuration : CF
|
|
|
|
if msg[0] ==67 and msg[1] ==70 : # Code ASCII : 67 (C) puis 70 (F)
|
2022-11-05 05:08:39 +01:00
|
|
|
display.scroll ("CF")
|
|
|
|
radio.send("CF")
|
|
|
|
|
|
|
|
# Boucle d'écoute spécifique à la configuration
|
|
|
|
while True:
|
|
|
|
while not uart.any(): # Attente d'un message
|
|
|
|
pass
|
|
|
|
display.show(' ')
|
|
|
|
msg = uart.readline()
|
2022-11-06 14:49:34 +01:00
|
|
|
if msg[0] ==70 and msg[1] ==67 : # Code ASCII : 70 (F) puis 67 (C) -> fin de la configuration
|
2022-11-05 05:08:39 +01:00
|
|
|
break
|
|
|
|
# display.scroll (msg[:-1])
|
|
|
|
radio.send(str(msg[:-1]))
|
|
|
|
# display.scroll ("FC")
|
|
|
|
radio.send("FC")
|
2022-11-05 02:20:39 +01:00
|
|
|
|
|
|
|
# Fin : FI
|
|
|
|
if msg[0] ==70 and msg[1] ==73 : # Code ASCII : 70 (F) puis 73 (I)
|
2022-11-06 14:49:34 +01:00
|
|
|
radio.send("FI")
|
2022-11-05 02:20:39 +01:00
|
|
|
display.show(attente_image) # Témoin de fonctionnement
|
2022-11-04 19:37:55 +01:00
|
|
|
|
2022-11-04 16:30:35 +01:00
|
|
|
sleep(400)
|