-
Notifications
You must be signed in to change notification settings - Fork 0
/
servo.py
133 lines (117 loc) · 2.17 KB
/
servo.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import RPi.GPIO as GPIO
import time
# server GPIOs: fan = 3, lights = 18, 7
fan = False
aircon = False
temp = 0
fan_pin = 3
light_on_pin = 7
light_off_pin = 18
def reset_all():
GPIO.cleanup()
GPIO.setmode(GPIO.BOARD)
return None
def setup_servo(pin_num):
GPIO.setup(pin_num, GPIO.OUT)
p1 = GPIO.PWM(pin_num, 50)
return p1
def move_servo(pin_num, pos):
GPIO.setmode(GPIO.BOARD)
p1 = setup_servo(pin_num)
p1.start(pos)
time.sleep(0.5)
p1.stop()
GPIO.cleanup()
return None
# input = {0, 1, 2, 3, 4, 5} where 0 = off
def set_wind(val):
val = int(val)
pos = [2.5, 4.5, 6.5, 8.5, 10.5, 12.5]
global fan
if fan == True:
move_servo(fan_pin, pos[val])
print "adjusted"
else:
print "please turn on to adjust"
return None
# input = {On, Off}
def set_fan(val):
global fan
if val == "On":
fan = True
move_servo(fan_pin, 9)
print "turned on"
else:
fan = False
move_servo(fan_pin, 2.3)
print "turned off"
return None
# input = {On, Off}
def set_lights(val):
if val == "On":
move_servo(light_on_pin, 3)
print "turned on"
else:
move_servo(light_off_pin, 12)
print "turned off"
time.sleep(1)
move_servo(light_on_pin, 8)
move_servo(light_off_pin, 8)
return None
# input = {On, Off}
def set_aircon(val):
global aircon
if val == "On":
print "turned on"
val = True
else:
print "turned off"
val = False
if val != aircon:
print "changed"
# TO DO:
# (requires hardware config)
# press power button
# wait a sec
aircon = val
return None
# input = integer 1-16ish
def set_temp(val):
val = int(val)
global temp
change = val-temp
if change == 0:
"no change"
elif change < 0:
for i in range(-change):
print "decreasing.."
# TO DO:
# push down button
# hold
# release
# pause
print "decreased"
else:
for i in range(change):
print "increasing..."
# TO DO:
# push up button
# hold
# release
# pause
print "increased"
temp = val
return None
# needed to make sure of starting position for temp
def bottom_out_temp():
for i in range(20):
print "decreasing"
# TO DO:
# push down button
# hold
# release
# pause
print "temp decreased as much as possible"
global temp
temp = 0
return None