55 lines
1.2 KiB
Python
55 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import time
|
|
import sys
|
|
import serial
|
|
|
|
|
|
SERIAL_PORT = "/dev/cu.usbserial-A700e0gN"
|
|
SERIAL_SPEED = 9600
|
|
#SERIAL_SPEED = 19200
|
|
#SERIAL_SPEED = 115200
|
|
|
|
|
|
arduino = serial.Serial(port=SERIAL_PORT, baudrate=SERIAL_SPEED, timeout=.1)
|
|
|
|
|
|
def write_read(x):
|
|
arduino.write(bytes(x, 'utf-8'))
|
|
time.sleep(0.05)
|
|
data = arduino.readline()
|
|
return data
|
|
|
|
|
|
def countdown(start: int):
|
|
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 main():
|
|
while True:
|
|
num = int(input("Enter a number (-1=exit): "))
|
|
if num < 0:
|
|
sys.exit(0)
|
|
#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("ECHO C " + str(num) + "\r\n", 'utf8'))
|
|
countdown(num)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
try:
|
|
main()
|
|
except KeyboardInterrupt:
|
|
print("^C", file=sys.stderr)
|
|
|