mapid/mapid-count.py
2023-10-15 18:01:09 +02:00

68 lines
1.4 KiB
Python
Executable file

#!/usr/bin/env python3
import time
import sys
import serial
import mapid
# print(mapid.get_serial_dev()); sys.exit(1)
SERIAL_DEV = mapid.get_serial_dev()
SERIAL_SPEED = mapid.get_serial_speed()
def write_read(x):
arduino = serial.Serial(port=SERIAL_DEV, baudrate=SERIAL_SPEED, timeout=.1)
arduino.write(bytes(x, 'utf-8'))
time.sleep(0.05)
data = arduino.readline()
return data
def countdown(start: int):
arduino = serial.Serial(port=SERIAL_DEV, baudrate=SERIAL_SPEED, timeout=.1)
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'))
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!!!")
def main():
while True:
num = int(input("Enter a number (-1=exit): "))
if num < 0:
sys.exit(0)
# countdown(num)
countdown2(num)
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("^C", file=sys.stderr)