Added a countdown Python script
This commit is contained in:
parent
607b126708
commit
c9d860ab61
2 changed files with 59 additions and 0 deletions
55
mapid-count.py
Normal file
55
mapid-count.py
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
#!/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)
|
||||||
|
|
4
requirements.txt
Normal file
4
requirements.txt
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
# requirements.txt
|
||||||
|
|
||||||
|
serial
|
||||||
|
|
Loading…
Reference in a new issue