-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadSerial.py
37 lines (29 loc) · 863 Bytes
/
readSerial.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# arduino_LED_user.py
import serial
import time
# Define the serial port and baud rate.
# Ensure the 'COM#' corresponds to what was seen in the Windows Device Manager
ser = serial.Serial('COM4', 9600)
def led_on_off():
user_input = input("\n Type on / off / quit : ")
if user_input == "on":
print("LED is on...")
time.sleep(0.1)
ser.write(b'H')
led_on_off()
elif user_input == "off":
print("LED is off...")
time.sleep(0.1)
ser.write(b'L')
led_on_off()
elif user_input == "quit" or user_input == "q":
print("Program Exiting")
time.sleep(0.1)
ser.write(b'L')
ser.close()
else:
print("Invalid input. Type on / off / quit.")
led_on_off()
time.sleep(2) # wait for the serial connection to initialize
led_on_off()
# test commit