mapid/mapid-count.py

69 lines
1.4 KiB
Python
Raw Permalink Normal View History

2023-10-15 11:13:52 +02:00
#!/usr/bin/env python3
import time
import sys
import serial
2023-10-15 18:01:09 +02:00
import mapid
2023-10-15 11:13:52 +02:00
2023-10-15 18:01:09 +02:00
# print(mapid.get_serial_dev()); sys.exit(1)
SERIAL_DEV = mapid.get_serial_dev()
SERIAL_SPEED = mapid.get_serial_speed()
2023-10-15 11:13:52 +02:00
def write_read(x):
2023-10-15 18:01:09 +02:00
arduino = serial.Serial(port=SERIAL_DEV, baudrate=SERIAL_SPEED, timeout=.1)
2023-10-15 11:13:52 +02:00
arduino.write(bytes(x, 'utf-8'))
time.sleep(0.05)
data = arduino.readline()
return data
def countdown(start: int):
2023-10-15 18:01:09 +02:00
arduino = serial.Serial(port=SERIAL_DEV, baudrate=SERIAL_SPEED, timeout=.1)
2023-10-15 11:13:52 +02:00
for i in range(start, -1, -1):
arduino.write(bytes("CLS\r\n", 'utf8'))
arduino.write(bytes("LINE 1\r\n", 'utf8'))
arduino.write(bytes("ECHO Countdown\r\n", 'utf8'))
arduino.write(bytes("LINE 2\r\n", 'utf8'))
print(str(i))
arduino.write(bytes("ECHO " + str(i) + "\r\n", 'utf8'))
time.sleep(1)
arduino.write(bytes("CLS\r\n", 'utf8'))
arduino.write(bytes("LINE 2\r\n", 'utf8'))
arduino.write(bytes("ECHO BOOM!!!\r\n", 'utf8'))
2023-10-15 18:01:09 +02:00
def countdown2(start: int):
m = mapid.MAPID_CP()
m.cls()
for i in range(start, -1, -1):
m.cls()
m.line(1)
m.echo("Countdown")
m.line(2)
print("\t" + str(i))
m.echo(str(i))
time.sleep(1)
m.cls()
m.line(2)
m.echo("BOOM!!!")
2023-10-15 11:13:52 +02:00
def main():
while True:
num = int(input("Enter a number (-1=exit): "))
if num < 0:
sys.exit(0)
2023-10-15 18:01:09 +02:00
# countdown(num)
countdown2(num)
2023-10-15 11:13:52 +02:00
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("^C", file=sys.stderr)