From 4b6d5da4bd4b777e204bde4f5ec9c87a81e9ecd5 Mon Sep 17 00:00:00 2001 From: "Vincent N." <vincent.namy@edu.ge.ch> Date: Mon, 3 Mar 2025 23:16:07 +0100 Subject: [PATCH] =?UTF-8?q?[T=C3=A9l=C3=A9commande]=20Ajout=20code=20t?= =?UTF-8?q?=C3=A9l=C3=A9commande=20+=20dessin=20pc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Telecommande/main_pc.py | 25 +++++++++++++++++++++ Telecommande/main_robot.py | 25 +++++++++++++++++++++ Telecommande/main_telecommande.py | 26 ++++++++++++++++++++++ Telecommande/pc.py | 37 +++++++++++++++++++++++++++++++ 4 files changed, 113 insertions(+) create mode 100644 Telecommande/main_pc.py create mode 100644 Telecommande/main_robot.py create mode 100644 Telecommande/main_telecommande.py create mode 100644 Telecommande/pc.py diff --git a/Telecommande/main_pc.py b/Telecommande/main_pc.py new file mode 100644 index 0000000..bf496a1 --- /dev/null +++ b/Telecommande/main_pc.py @@ -0,0 +1,25 @@ +''' +Gestion télécommande Pour Micro:bit OC Robotique 2025 +Auteur·ice : Vincent Namy +Version : 1.0 +Date : 3.2.25 + +''' +from microbit import * +from protocole import * +display.off() + +if __name__ == '__main__': + + userId = 1 + destId = 0 + + # Main + while True: + sleep(10) + m = receive_msg(userId) + if m and m.msgId==73: + print("x", m.payload[0]*4, "y", m.payload[1]*4, "z", m.payload[2]) + + + diff --git a/Telecommande/main_robot.py b/Telecommande/main_robot.py new file mode 100644 index 0000000..bf496a1 --- /dev/null +++ b/Telecommande/main_robot.py @@ -0,0 +1,25 @@ +''' +Gestion télécommande Pour Micro:bit OC Robotique 2025 +Auteur·ice : Vincent Namy +Version : 1.0 +Date : 3.2.25 + +''' +from microbit import * +from protocole import * +display.off() + +if __name__ == '__main__': + + userId = 1 + destId = 0 + + # Main + while True: + sleep(10) + m = receive_msg(userId) + if m and m.msgId==73: + print("x", m.payload[0]*4, "y", m.payload[1]*4, "z", m.payload[2]) + + + diff --git a/Telecommande/main_telecommande.py b/Telecommande/main_telecommande.py new file mode 100644 index 0000000..11b9b4e --- /dev/null +++ b/Telecommande/main_telecommande.py @@ -0,0 +1,26 @@ +''' +Gestion télécommande Pour Micro:bit OC Robotique 2025 +Auteur·ice : Vincent Namy +Version : 1.0 +Date : 3.2.25 + +''' +from microbit import * +from protocole import * +display.off() + +if __name__ == '__main__': + + userId = 0 + destId = 1 + + # Main + while True: + sleep(10) + print("x", pin4.read_analog()//4, "y", pin3.read_analog()//4, "z", pin5.read_digital()) + + payload = [pin4.read_analog()//4, pin3.read_analog()//4, pin5.read_digital()] + print("sent : ", send_msg(73,payload,userId, destId)) + + + diff --git a/Telecommande/pc.py b/Telecommande/pc.py new file mode 100644 index 0000000..5aefb39 --- /dev/null +++ b/Telecommande/pc.py @@ -0,0 +1,37 @@ +import serial +from turtle import * + +# Configuration du port série +port = "/dev/ttyACM1" +baudrate = 115200 +bytesize = serial.EIGHTBITS +parity = serial.PARITY_NONE +stopbits = serial.STOPBITS_ONE +timeout = 1 + +# Ouverture du port série +ser = serial.Serial(port, baudrate, bytesize, parity, stopbits, timeout) +penup() +lastZ = 0 +ecrire = False +while True: + # Lecture des données disponibles sur le port série + line = ser.readline().decode() + + # Affichage des données reçues + if line and len(line)>1: + s = line.split() + if len(s)>5: + x= int(s[1])-(512+16) + y= int(s[3])-(512-4) + z = int(s[5]) + print(x, y) + if z and not lastZ: + ecrire = not ecrire + if ecrire : + pendown() + else: + penup() + goto(xcor()+x//10, ycor()+y//10) + lastZ = z + \ No newline at end of file -- GitLab