-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
44 lines (34 loc) · 1.22 KB
/
test.py
File metadata and controls
44 lines (34 loc) · 1.22 KB
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
38
39
40
41
42
43
44
# import serial
# import time
# # Open serial port, make sure to update the port name
# ser = serial.Serial('COM9', 9600, timeout=1)
# # Wait for Arduino to reset
# time.sleep(2)
# try:
# while True:
# # Send data to Arduino
# command = input("Enter command (1 for ON, 0 for OFF): ")
# ser.write(command.encode())
# # Wait for response
# response = ser.readline().decode().strip()
# print("Arduino:", response)
# except KeyboardInterrupt:
# print("DFdfdf")
# ser.close() # Close the serial port on keyboard interrupt
import serial
import time
# Open serial port, make sure to update the port name
# On Mac, the port name is usually something like '/dev/tty.usbmodemXXXX'
ser = serial.Serial('COM9', 9600, timeout=1) # Replace 'XXXX' with the appropriate number
# Wait for Arduino to reset
time.sleep(2)
try:
while True:
# Send data to Arduino
command = input("Enter command (1 for ON, 0 for OFF): ")
ser.write(command.encode())
# Wait for response
# response = ser.readline().decode().strip()
# print("Arduino:", response)
except KeyboardInterrupt:
ser.close() # Close the serial port on keyboard interrupt