-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdimmerControl.py
executable file
·44 lines (36 loc) · 977 Bytes
/
dimmerControl.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
38
39
40
41
42
43
44
import time
import serial
import sys
import threading
class bcolors:
YELLOW = '\033[93m'
RED = '\033[1;31m'
BLACK = ''
BLUE = '\033[1;34m'
try:
ser = serial.Serial('/dev/ttyUSB0', 9600)
except:
print 'No serial. I quit.'
sys.exit(0)
while True:
command = None
while not command:
try:
command = int(raw_input(bcolors.BLUE + 'What is your command? '))
ser.write(chr(command))
except ValueError:
if command == 104:
print 'Help'
else:
print bcolors.RED + 'Invalid Number'
message = ord(ser.read())
# print(ord(message))
if message == 0:
print bcolors.RED + 'Error, wrong command issued.'
elif message == 1:
print bcolors.RED + '1 of 2 commands acknowled.'
elif message == 2:
print bcolors.RED + '2 of 2 commands acknowled.'
else:
print bcolors.RED + '???'
time.sleep(0.5)