diff --git a/ropy-29.blend b/ropy-29.blend index 57da0f8..1b72aa0 100644 Binary files a/ropy-29.blend and b/ropy-29.blend differ diff --git a/rp.py b/rp.py index 735ce70..4b28485 100644 --- a/rp.py +++ b/rp.py @@ -7,10 +7,11 @@ import numpy as np import time import sys import os -import webbrowser +import webbrowser # Lien internet import threading # Multithreading import xml.etree.ElementTree as ET # Creating/parsing XML file -import runpy +import runpy # Execution de script Python légère (sans import) +# import serial # Liaison série (jumeau numérique) import rp_map1 as rp_map # Map definition import rp_doc # Documentation @@ -125,6 +126,15 @@ def points_maj (cont): obj=scene.objects['Rover'] obj['w_position']=str(round(obj.worldPosition.x,3))+","+str(round(obj.worldPosition.y,3))+","+str(round(obj.worldPosition.z,3)) + # Jumeau numérique + # if scene.objects['Commands']['twins'] and scene.objects['Points-Twins'].visible == False: + # scene.objects['Points-Twins'].setVisible(True,True) + # scene.objects['Points-Twins-text'].setVisible(True,False) + + # scene.objects['Commands']['twins_port'] = port + # scene.objects['Commands']['twins_speed'] = speed + # scene.objects['Commands']['twins'] = True + ############################################################################### # Terrain ############################################################################### @@ -431,6 +441,8 @@ def cmd_init(): scene.objects['Grid-v'].setVisible(False,True) scene.objects['Points-Map-text']['Text']="" scene.objects['Points-Map-text'].setVisible(True,False) + scene.objects['Points-Twins'].setVisible(False,True) + scene.objects['Points-Twins-text'].setVisible(False,False) # scene.objects['Info-1-text'].setVisible(False,False) # scene.objects['Info-2-text'].setVisible(False,False) @@ -1017,6 +1029,9 @@ def tablet_close (): # Overlay scene.objects['Points'].setVisible(True,True) + if scene.objects['Commands']['twins'] ==False: + scene.objects['Points-Twins'].setVisible(False,True) + scene.objects['Points-Twins-text'].setVisible(False,False) scene.objects['Commands'].setVisible(True,True) scene.objects['Camera'].setVisible(True,True) scene.active_camera = scene.objects["Camera"] @@ -1258,6 +1273,9 @@ def store_close(): # Overlay scene.objects['Points'].setVisible(True,True) + if scene.objects['Commands']['twins'] ==False: + scene.objects['Points-Twins'].setVisible(False,True) + scene.objects['Points-Twins-text'].setVisible(False,False) scene.objects['Commands'].setVisible(True,True) scene.objects['Camera'].setVisible(True,True) scene.active_camera = scene.objects["Camera"] diff --git a/rp_cmd.py b/rp_cmd.py index 401abb6..29ed95b 100644 --- a/rp_cmd.py +++ b/rp_cmd.py @@ -29,6 +29,12 @@ from rp_lib import * # Bibliothèque Ropy def commandes(): # Ecrire votre code ici ... + rp_jumeau('/dev/ttyACM0', 115200) + + rp_avancer() + rp_gauche() + rp_avancer() + rp_avancer() rp_fin() # A garder diff --git a/rp_config.xml b/rp_config.xml index aae8bf8..64254cd 100644 --- a/rp_config.xml +++ b/rp_config.xml @@ -1,6 +1,6 @@ - 1.0 + 4.0 False 0.0057830810546875 @@ -14,7 +14,7 @@ 1 - 1 + 2 False diff --git a/rp_lib.py b/rp_lib.py index 02ad3fc..954deb3 100644 --- a/rp_lib.py +++ b/rp_lib.py @@ -29,13 +29,6 @@ import rp_map1 as rp_map # Map definition scene = bge.logic.getCurrentScene() debug_mvt = scene.objects['Terrain']['debug_mvt'] -# twins = scene.objects['Terrain']['twins'] -twins=True - -# Paramétrage de la communication avec la carte de communication (Arduino, Micro:bit) -#serial_port='COM5' # Windows -serial_port='/dev/ttyACM0' # GNU/Linux -serial_baud=9600 # 115200 # Sounds audiodev = aud.Device() @@ -46,6 +39,9 @@ threads_cmd=[] threads_gostore=[] debug_thread = scene.objects['Terrain']['debug_thread'] +# Jumeau numérique +twins_serial = None + # UPBGE constants JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED JUST_RELEASED = bge.logic.KX_INPUT_JUST_RELEASED @@ -209,7 +205,7 @@ def rp_avancer (): if debug_mvt: print ("rp_avancer()") scene.objects['Points']['step'] +=1 - if twins: + if scene.objects['Commands']['twins']: serial_msg = "a\n" serial_comm.write(serial_msg.encode()) # Communication série : modele 3d -> carte communication ( arduino | micro:bit ) @@ -330,7 +326,7 @@ def rp_reculer (): if (debug_mvt): print ("rp_reculer()") scene.objects['Points']['step'] +=1 - if twins: + if scene.objects['Commands']['twins']: serial_msg = "r\n" serial_comm.write(serial_msg.encode()) # Communication série : modele 3d -> carte communication ( arduino | micro:bit ) @@ -399,7 +395,7 @@ def rp_gauche (): print ("rp_gauche()") scene.objects['Points']['step'] +=1 step=math.pi/2 # Pas angulaire - if twins: + if scene.objects['Commands']['twins']: serial_msg = "g\n" serial_comm.write(serial_msg.encode()) # Communication série : modele 3d -> carte communication ( arduino | micro:bit ) @@ -448,7 +444,7 @@ def rp_droite (): print ("rp_droite()") scene.objects['Points']['step'] +=1 step=math.pi/2 # Pas angulaire - if twins: + if scene.objects['Commands']['twins']: serial_msg = "d\n" serial_comm.write(serial_msg.encode()) # Communication série : modele 3d -> carte communication ( arduino | micro:bit ) @@ -492,9 +488,12 @@ def rp_marquer (): if obj['stop']: return False - # Points et console + # Points, console et jumeau numérique if (debug_mvt): print ("rp_marquer() -> balise #"+ str(len(scene.objects['Terrain']['map_tile_beacon']))) + if scene.objects['Commands']['twins']: + serial_msg = "m\n" + serial_comm.write(serial_msg.encode()) # Communication série : modele 3d -> carte communication ( arduino | micro:bit ) rp_tempo (0.1) x = obj.worldPosition.x y = obj.worldPosition.y @@ -761,8 +760,8 @@ def rp_batterie (): def rover_colision_montain (back): obj=scene.objects['Rover'] - # Jumeau - if twins: + # Jumeau numérique + if scene.objects['Commands']['twins']: serial_msg = "c\n" serial_comm.write(serial_msg.encode()) # Communication série : modele 3d -> carte communication ( arduino | micro:bit ) @@ -821,8 +820,8 @@ def rover_colision_montain (back): def rover_colision_station (back): obj=scene.objects['Rover'] - # Jumeau - if twins: + # Jumeau numérique + if scene.objects['Commands']['twins']: serial_msg = "c\n" serial_comm.write(serial_msg.encode()) # Communication série : modele 3d -> carte communication ( arduino | micro:bit ) @@ -989,8 +988,8 @@ def rover_drill (x,y): scene.objects['Sun'].applyMovement((0, 0, 0), True) rp_tempo (0.1) - # Jumeau - if twins: + # Jumeau numérique + if scene.objects['Commands']['twins']: serial_msg = "f\n" serial_comm.write(serial_msg.encode()) # Communication série : modele 3d -> carte communication ( arduino | micro:bit ) @@ -1068,7 +1067,7 @@ def rover_drill (x,y): # if "tile_dirtHigh" in obj_i.name: # if round(obj_i.worldPosition.x) == x and round(obj_i.worldPosition.y) == y : # obj_i.setVisible(False, True) - + ############################################################################### # Temporisation ############################################################################### @@ -1086,6 +1085,47 @@ def rp_tempo (duration): time.sleep(0.001) # # pass +############################################################################### +# Jumeau numérique +############################################################################### + +# Paramétrage de la communication avec la carte de communication (Arduino, Micro:bit) + +def rp_jumeau(port, speed): + scene.objects['Points-Twins'].setVisible(True,True) + scene.objects['Points-Twins-text'].setVisible(True,False) + + twins_serial = getSerialOrNone(port,speed) + if twins_serial is not None: + scene.objects['Commands']['twins'] = True + scene.objects['Commands']['twins_port'] = port + scene.objects['Commands']['twins_speed'] = speed + scene.objects['Points-Twins-text']['Text'] = "Connection\nétablie" + print (twins_serial) + else: + scene.objects['Commands']['twins'] = False + scene.objects['Points-Twins-text']['Text'] = "Port pas \nprêt" + + # ser = serial.Serial('/dev/ttyACM0',38400) # 6 fps + # ser = serial.Serial('/dev/ttyACM0',9600) # 2 fps + #serial_port='COM5' # Windows + # serial_port='/dev/ttyACM0' # GNU/Linux + # 115200 -> 7 fps + # 38400 -> 6 fps + # 9600 -> 2 fps + +def getSerialOrNone(port,speed): + try: + return serial.Serial(port,speed) + except: + return None + +def rp_jumeau_close(): + twins_serial.close() # Fermer proprement le port série + scene.objects['Commands']['twins'] = False + scene.objects['Points-Twins'].setVisible(False,True) + scene.objects['Points-Twins-text'].setVisible(False,False) + ############################################################################### # Fonction bas niveau ############################################################################### diff --git a/rp_store.py b/rp_store.py index c261e68..729fd91 100644 --- a/rp_store.py +++ b/rp_store.py @@ -87,11 +87,11 @@ def open2 (cont): scene.objects['Camera'].setVisible(False,True) # Animation de la bulle - scene.objects['Bubble-1-text']['Text']="Salut !\n Souhaites tu\n acquerir des\n nouvelles\n ameliorations ?\n" + scene.objects['Bubble-1-text']['Text']="Salut mon ami !\n Souhaites tu\n acquerir des\n nouvelles\n ameliorations ?\n" if scene.objects['Points']['upgrade_nb'] == 4 : scene.objects['Bubble-1-text']['Text']="Resalut ! \n Rien de neuf \n pour le moment. \n Il fait beau \n aujourd'hui, non ?" if scene.objects['Points']['upgrade_nb'] < 4 and scene.objects['Points']['upgrade_credit']==0: - scene.objects['Bubble-1-text']['Text']="Salut ! Si tu veux \n des nouvelles \n ameliorations,\n il te faut passer \n des missions !" + scene.objects['Bubble-1-text']['Text']="Des missions \n tu passeras, \n des crédits \n tu auras !" start = 1 end = 20 diff --git a/twins/microbit-lecteur_portserie.py b/twins/microbit-lecteur_portserie.py new file mode 100644 index 0000000..85cc99e --- /dev/null +++ b/twins/microbit-lecteur_portserie.py @@ -0,0 +1,20 @@ +from microbit import uart, sleep +from microbit import * + +############################################################################### +# microbit-lecteur_portserie.py +# @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 + pass + + display.scroll('ok : ') # Réception d'une message + content = uart.readline() + display.scroll(content[:-1]) # Affichage du message sans le '/n' + sleep(400) diff --git a/twins/rp_maqueen-relay.py b/twins/rp_maqueen-relay.py new file mode 100644 index 0000000..1fc503f --- /dev/null +++ b/twins/rp_maqueen-relay.py @@ -0,0 +1,38 @@ +from microbit import uart, sleep +from microbit import * + +############################################################################### +# rp_twins_maqueen-relay.py +# @title: Jumeau Maqueen : Programme de la carte microbit du relai +# @project: Ropy (Blender-EduTech) +# @lang: fr +# @authors: Philippe Roy +# @copyright: Copyright (C) 2022 Philippe Roy +# @license: GNU GPL +############################################################################### + +############################################################################### +# Initialisation +############################################################################### + +led_image = Image("00000:00000:00900:00000:00000") +display.show(led_image) # Témoin de fonctionnement +# display.scroll("Maqueen manette") +radio.config(group=1) +radio.on() + +uart.init(baudrate= 115200) # Initialisation du port série + +############################################################################### +# Écoute du port série en relayage vers la radio +############################################################################### + +while True: + + while not uart.any(): # Attente d'un message + pass + + display.scroll('ok : ') # Réception d'une message + content = uart.readline() + display.scroll(content[:-1]) # Affichage du message sans le '/n' + sleep(400) diff --git a/twins/rp_maqueen-relay.py.~1~ b/twins/rp_maqueen-relay.py.~1~ new file mode 100644 index 0000000..e4cf679 --- /dev/null +++ b/twins/rp_maqueen-relay.py.~1~ @@ -0,0 +1,24 @@ +from microbit import uart, sleep +from microbit import * + +############################################################################### +# rp_twins_maqueen-beacon.py +# @title: Jumeau Maqueen : Programme de la carte microbit du relai +# @project: Ropy (Blender-EduTech) +# @lang: fr +# @authors: Philippe Roy +# @copyright: Copyright (C) 2022 Philippe Roy +# @license: GNU GPL +############################################################################### + +uart.init(baudrate= 115200) # Initialisation du port série + +while True: + + while not uart.any(): # Attente d'un message + pass + + display.scroll('ok : ') # Réception d'une message + content = uart.readline() + display.scroll(content[:-1]) # Affichage du message sans le '/n' + sleep(400) diff --git a/twins/rp_maqueen-robot.py b/twins/rp_maqueen-robot.py new file mode 100755 index 0000000..54133a7 --- /dev/null +++ b/twins/rp_maqueen-robot.py @@ -0,0 +1,113 @@ +from microbit import * +from machine import * +import music +import radio + +############################################################################### +# rp_maqueen-robot.py +# @title: Jumeau Maqueen : Programme de la carte microbit du robot +# @project: Ropy (Blender-EduTech) +# @lang: fr +# @authors: Philippe Roy +# @copyright: Copyright (C) 2022 Philippe Roy +# @license: GNU GPL +# +# Programme d'execution des ordres de la manette pour le robot Maqueen# +############################################################################### + +# ############################################################################### +# Initialisation +# ############################################################################### + +led_image = Image('00000:00000:00900:00000:00000') +display.show(led_image) # Témoin de fonctionnement +radio.config(group=1, queue=1, length=8) +radio.on() + +# ############################################################################### +# Boucle principale +# ############################################################################### + +while True: + + v_avancer = 50 + v_tourner = 50 + v_tourner_faible = 25 + + # Lecture de l'ordre + ordre=radio.receive() + + # Avancer + if ordre=="AV": + display.show(Image.ARROW_N) + pin8.write_digital(1) # Led avant gauche + pin12.write_digital(1) # Led avant gauche + i2c.write(0x10, bytearray([0x00, 0x0, v_avancer])) # Moteur gauche + i2c.write(0x10, bytearray([0x02, 0x0, v_avancer])) # Moteur droit + + # Reculer + if ordre=="RE": + display.show(Image.ARROW_S) + pin8.write_digital(1) # Led avant gauche + pin12.write_digital(1) # Led avant gauche + i2c.write(0x10, bytearray([0x00, 0x1, v_avancer])) # Moteur gauche + i2c.write(0x10, bytearray([0x02, 0x1, v_avancer])) # Moteur droit + + # Gauche + if ordre=="GA": + display.show(Image.ARROW_W) + pin8.write_digital(1) # Led avant gauche + pin12.write_digital(0) # Led avant droit + i2c.write(0x10, bytearray([0x00, 0x0, 0])) # Moteur gauche + i2c.write(0x10, bytearray([0x02, 0x0, v_tourner])) # Moteur droit + + # Avancer + gauche + if ordre=="AG": + display.show(Image.ARROW_W) + pin8.write_digital(1) # Led avant gauche + pin12.write_digital(0) # Led avant droit + i2c.write(0x10, bytearray([0x00, 0x0, v_tourner_faible])) # Moteur gauche + i2c.write(0x10, bytearray([0x02, 0x0, v_tourner])) # Moteur droit + + # Reculer + gauche + if ordre=="RG": + display.show(Image.ARROW_W) + pin8.write_digital(1) # Led avant gauche + pin12.write_digital(0) # Led avant droit + i2c.write(0x10, bytearray([0x00, 0x1, v_tourner_faible])) # Moteur gauche + i2c.write(0x10, bytearray([0x02, 0x1, v_tourner])) # Moteur droit + + # Droite + if ordre=="DR": + display.show(Image.ARROW_E) + pin8.write_digital(0) # Led avant gauche + pin12.write_digital(1) # Led avant droit + i2c.write(0x10, bytearray([0x00, 0x0, v_tourner])) # Moteur gauche + i2c.write(0x10, bytearray([0x02, 0x0, 0])) # Moteur droit + + # Avancer + droite + if ordre=="AD": + display.show(Image.ARROW_W) + pin8.write_digital(1) # Led avant gauche + pin12.write_digital(0) # Led avant droit + i2c.write(0x10, bytearray([0x00, 0x0, v_tourner])) # Moteur gauche + i2c.write(0x10, bytearray([0x02, 0x0, v_tourner_faible])) # Moteur droit + + # Reculer + droite + if ordre=="RD": + display.show(Image.ARROW_W) + pin8.write_digital(1) # Led avant gauche + pin12.write_digital(0) # Led avant droit + i2c.write(0x10, bytearray([0x00, 0x1, v_tourner])) # Moteur gauche + i2c.write(0x10, bytearray([0x02, 0x1, v_tourner_faible])) # Moteur droit + + # Stop + if ordre=="ST": + display.show(led_image) # Témoin de fonctionnement + pin8.write_digital(0) # Led avant gauche + pin12.write_digital(0) # Led avant droit + i2c.write(0x10, bytearray([0x00, 0x0, 0])) + i2c.write(0x10, bytearray([0x02, 0x1, 0])) + + # Cadencement + # sleep(10) diff --git a/twins/rp_maqueen-robot.py.~1~ b/twins/rp_maqueen-robot.py.~1~ new file mode 100755 index 0000000..5f7284c --- /dev/null +++ b/twins/rp_maqueen-robot.py.~1~ @@ -0,0 +1,113 @@ +from microbit import * +from machine import * +import music +import radio + +############################################################################### +# rp_twins_maqueen-robot.py +# @title: Jumeau Maqueen : Programme de la carte microbit du robot +# @project: Ropy (Blender-EduTech) +# @lang: fr +# @authors: Philippe Roy +# @copyright: Copyright (C) 2022 Philippe Roy +# @license: GNU GPL +# +# Programme d'execution des ordres de la manette pour le robot Maqueen# +############################################################################### + +# ############################################################################### +# Initialisation +# ############################################################################### + +led_image = Image('00000:00000:00900:00000:00000') +display.show(led_image) # Témoin de fonctionnement +radio.config(group=1, queue=1, length=8) +radio.on() + +# ############################################################################### +# Boucle principale +# ############################################################################### + +while True: + + v_avancer = 50 + v_tourner = 50 + v_tourner_faible = 25 + + # Lecture de l'ordre + ordre=radio.receive() + + # Avancer + if ordre=="AV": + display.show(Image.ARROW_N) + pin8.write_digital(1) # Led avant gauche + pin12.write_digital(1) # Led avant gauche + i2c.write(0x10, bytearray([0x00, 0x0, v_avancer])) # Moteur gauche + i2c.write(0x10, bytearray([0x02, 0x0, v_avancer])) # Moteur droit + + # Reculer + if ordre=="RE": + display.show(Image.ARROW_S) + pin8.write_digital(1) # Led avant gauche + pin12.write_digital(1) # Led avant gauche + i2c.write(0x10, bytearray([0x00, 0x1, v_avancer])) # Moteur gauche + i2c.write(0x10, bytearray([0x02, 0x1, v_avancer])) # Moteur droit + + # Gauche + if ordre=="GA": + display.show(Image.ARROW_W) + pin8.write_digital(1) # Led avant gauche + pin12.write_digital(0) # Led avant droit + i2c.write(0x10, bytearray([0x00, 0x0, 0])) # Moteur gauche + i2c.write(0x10, bytearray([0x02, 0x0, v_tourner])) # Moteur droit + + # Avancer + gauche + if ordre=="AG": + display.show(Image.ARROW_W) + pin8.write_digital(1) # Led avant gauche + pin12.write_digital(0) # Led avant droit + i2c.write(0x10, bytearray([0x00, 0x0, v_tourner_faible])) # Moteur gauche + i2c.write(0x10, bytearray([0x02, 0x0, v_tourner])) # Moteur droit + + # Reculer + gauche + if ordre=="RG": + display.show(Image.ARROW_W) + pin8.write_digital(1) # Led avant gauche + pin12.write_digital(0) # Led avant droit + i2c.write(0x10, bytearray([0x00, 0x1, v_tourner_faible])) # Moteur gauche + i2c.write(0x10, bytearray([0x02, 0x1, v_tourner])) # Moteur droit + + # Droite + if ordre=="DR": + display.show(Image.ARROW_E) + pin8.write_digital(0) # Led avant gauche + pin12.write_digital(1) # Led avant droit + i2c.write(0x10, bytearray([0x00, 0x0, v_tourner])) # Moteur gauche + i2c.write(0x10, bytearray([0x02, 0x0, 0])) # Moteur droit + + # Avancer + droite + if ordre=="AD": + display.show(Image.ARROW_W) + pin8.write_digital(1) # Led avant gauche + pin12.write_digital(0) # Led avant droit + i2c.write(0x10, bytearray([0x00, 0x0, v_tourner])) # Moteur gauche + i2c.write(0x10, bytearray([0x02, 0x0, v_tourner_faible])) # Moteur droit + + # Reculer + droite + if ordre=="RD": + display.show(Image.ARROW_W) + pin8.write_digital(1) # Led avant gauche + pin12.write_digital(0) # Led avant droit + i2c.write(0x10, bytearray([0x00, 0x1, v_tourner])) # Moteur gauche + i2c.write(0x10, bytearray([0x02, 0x1, v_tourner_faible])) # Moteur droit + + # Stop + if ordre=="ST": + display.show(led_image) # Témoin de fonctionnement + pin8.write_digital(0) # Led avant gauche + pin12.write_digital(0) # Led avant droit + i2c.write(0x10, bytearray([0x00, 0x0, 0])) + i2c.write(0x10, bytearray([0x02, 0x1, 0])) + + # Cadencement + # sleep(10) diff --git a/twins/rp_twins-maqueen.py.~1~ b/twins/rp_twins-maqueen.py.~1~ new file mode 100755 index 0000000..74a2586 --- /dev/null +++ b/twins/rp_twins-maqueen.py.~1~ @@ -0,0 +1,114 @@ +from microbit import * +from machine import * +import music +import radio + +############################################################################### +# maqueen_robot.py: +# @title: Robot Maqueen +# @project: +# @lang: fr +# @authors: Philippe Roy +# @copyright: Copyright (C) 2022 Philippe Roy +# @license: GNU GPL +# +# Programme d'execution des ordres de la manette pour le robot Maqueen +# +############################################################################### + +# ############################################################################### +# Initialisation +# ############################################################################### + +led_image = Image('00000:00000:00900:00000:00000') +display.show(led_image) # Témoin de fonctionnement +radio.config(group=1, queue=1, length=8) +radio.on() + +# ############################################################################### +# Boucle principale +# ############################################################################### + +while True: + + v_avancer = 50 + v_tourner = 50 + v_tourner_faible = 25 + + # Lecture de l'ordre + ordre=radio.receive() + + # Avancer + if ordre=="AV": + display.show(Image.ARROW_N) + pin8.write_digital(1) # Led avant gauche + pin12.write_digital(1) # Led avant gauche + i2c.write(0x10, bytearray([0x00, 0x0, v_avancer])) # Moteur gauche + i2c.write(0x10, bytearray([0x02, 0x0, v_avancer])) # Moteur droit + + # Reculer + if ordre=="RE": + display.show(Image.ARROW_S) + pin8.write_digital(1) # Led avant gauche + pin12.write_digital(1) # Led avant gauche + i2c.write(0x10, bytearray([0x00, 0x1, v_avancer])) # Moteur gauche + i2c.write(0x10, bytearray([0x02, 0x1, v_avancer])) # Moteur droit + + # Gauche + if ordre=="GA": + display.show(Image.ARROW_W) + pin8.write_digital(1) # Led avant gauche + pin12.write_digital(0) # Led avant droit + i2c.write(0x10, bytearray([0x00, 0x0, 0])) # Moteur gauche + i2c.write(0x10, bytearray([0x02, 0x0, v_tourner])) # Moteur droit + + # Avancer + gauche + if ordre=="AG": + display.show(Image.ARROW_W) + pin8.write_digital(1) # Led avant gauche + pin12.write_digital(0) # Led avant droit + i2c.write(0x10, bytearray([0x00, 0x0, v_tourner_faible])) # Moteur gauche + i2c.write(0x10, bytearray([0x02, 0x0, v_tourner])) # Moteur droit + + # Reculer + gauche + if ordre=="RG": + display.show(Image.ARROW_W) + pin8.write_digital(1) # Led avant gauche + pin12.write_digital(0) # Led avant droit + i2c.write(0x10, bytearray([0x00, 0x1, v_tourner_faible])) # Moteur gauche + i2c.write(0x10, bytearray([0x02, 0x1, v_tourner])) # Moteur droit + + # Droite + if ordre=="DR": + display.show(Image.ARROW_E) + pin8.write_digital(0) # Led avant gauche + pin12.write_digital(1) # Led avant droit + i2c.write(0x10, bytearray([0x00, 0x0, v_tourner])) # Moteur gauche + i2c.write(0x10, bytearray([0x02, 0x0, 0])) # Moteur droit + + # Avancer + droite + if ordre=="AD": + display.show(Image.ARROW_W) + pin8.write_digital(1) # Led avant gauche + pin12.write_digital(0) # Led avant droit + i2c.write(0x10, bytearray([0x00, 0x0, v_tourner])) # Moteur gauche + i2c.write(0x10, bytearray([0x02, 0x0, v_tourner_faible])) # Moteur droit + + # Reculer + droite + if ordre=="RD": + display.show(Image.ARROW_W) + pin8.write_digital(1) # Led avant gauche + pin12.write_digital(0) # Led avant droit + i2c.write(0x10, bytearray([0x00, 0x1, v_tourner])) # Moteur gauche + i2c.write(0x10, bytearray([0x02, 0x1, v_tourner_faible])) # Moteur droit + + # Stop + if ordre=="ST": + display.show(led_image) # Témoin de fonctionnement + pin8.write_digital(0) # Led avant gauche + pin12.write_digital(0) # Led avant droit + i2c.write(0x10, bytearray([0x00, 0x0, 0])) + i2c.write(0x10, bytearray([0x02, 0x1, 0])) + + # Cadencement + # sleep(10) \ No newline at end of file diff --git a/twins/rp_twins-microbit.py.~1~ b/twins/rp_twins-microbit.py.~1~ new file mode 100644 index 0000000..85cc99e --- /dev/null +++ b/twins/rp_twins-microbit.py.~1~ @@ -0,0 +1,20 @@ +from microbit import uart, sleep +from microbit import * + +############################################################################### +# microbit-lecteur_portserie.py +# @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 + pass + + display.scroll('ok : ') # Réception d'une message + content = uart.readline() + display.scroll(content[:-1]) # Affichage du message sans le '/n' + sleep(400)