1
0
forked from tanchou/Verilog
This commit is contained in:
Gamenight77
2025-05-02 11:03:14 +02:00
parent 96c234de6d
commit 0faab53c30
29 changed files with 2769438 additions and 773 deletions

View File

@@ -0,0 +1,26 @@
import serial
# Configuration du port série
ser = serial.Serial(
port='COM6', # Remplace par ton port (ex : '/dev/ttyUSB0' sur Linux)
baudrate=115200,
timeout=1 # 1 seconde d'attente max pour la lecture
)
print("Lecture série en cours (Ctrl+C pour arrêter)...")
try:
while True:
if ser.in_waiting >= 2:
# Lecture des 2 octets (MSB en premier)
high_byte = ser.read()
low_byte = ser.read()
if high_byte and low_byte:
# Conversion en entier 16 bits
distance = (high_byte[0] << 8) | low_byte[0]
print(f"Distance mesurée : {high_byte}, {low_byte} cm")
except KeyboardInterrupt:
print("\nArrêt manuel.")
finally:
ser.close()