-
Notifications
You must be signed in to change notification settings - Fork 1
/
TransmitRF_OK.py
202 lines (191 loc) · 7.34 KB
/
TransmitRF_OK.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import time
import sys
import RPi.GPIO as GPIO
up = 'up'
up_1 = '101011100110111011011110101001000111111101111111111110100110110000'
up_2 = '101011100110111011011110101001000111111101111111111011011101111110'
down = 'down'
down_1 = '101011100110111011011110101001000111111101111111110111100101000000'
down_2 = '101011100110111011011110101001000111111101111111111011011101111110'
stop = 'stop'
stop_1 = '101011100110111011011110101001000111111101111111111011100110000000'
pause = 0.5
short_delay = 0.00018
long_delay = 0.00058
extended_delay = 0.00518
half_code_delay = 0.01033
NUM_ATTEMPTS = 4
TRANSMIT_PIN = 23
print "var settings done"
def transmit_code(code):
'''Transmit a chosen code string using the GPIO transmitter'''
print "entering code"
GPIO.setmode(GPIO.BCM)
GPIO.setup(TRANSMIT_PIN, GPIO.OUT)
GPIO.output(TRANSMIT_PIN, 0)
time.sleep(pause)
# UP COMMAND
if code is up or code == 100:
print "going up"
for t in range(NUM_ATTEMPTS):
print "entering for %s on %s" % (t, NUM_ATTEMPTS)
GPIO.output(TRANSMIT_PIN, 1)
time.sleep(extended_delay)
for i in up_1:
if i == '1':
GPIO.output(TRANSMIT_PIN, 1)
time.sleep(short_delay)
GPIO.output(TRANSMIT_PIN, 0)
time.sleep(long_delay)
print " 1 sent"
elif i == '0':
GPIO.output(TRANSMIT_PIN, 1)
time.sleep(long_delay)
GPIO.output(TRANSMIT_PIN, 0)
time.sleep(short_delay)
print " 0 sent"
else:
continue
GPIO.output(TRANSMIT_PIN, 0)
time.sleep(extended_delay)
print " extended delay sent"
print "out of for loop up_1"
time.sleep(half_code_delay)
print "adding half code delay"
for t in range(NUM_ATTEMPTS):
print "entering for %s on %s" % (t, NUM_ATTEMPTS)
GPIO.output(TRANSMIT_PIN, 1)
time.sleep(extended_delay)
for i in up_2:
if i == '1':
GPIO.output(TRANSMIT_PIN, 1)
time.sleep(short_delay)
GPIO.output(TRANSMIT_PIN, 0)
time.sleep(long_delay)
print " 1 sent"
elif i == '0':
GPIO.output(TRANSMIT_PIN, 1)
time.sleep(long_delay)
GPIO.output(TRANSMIT_PIN, 0)
time.sleep(short_delay)
print " 0 sent"
else:
continue
GPIO.output(TRANSMIT_PIN, 0)
time.sleep(extended_delay)
print " extended delay sent"
print "out of for loop up_2"
print "out of if up"
# END UP COMMAND
# DOWN COMMAND
if code is down or code == 0:
print "going down"
for t in range(NUM_ATTEMPTS):
print "entering for %s on %s" % (t, NUM_ATTEMPTS)
GPIO.output(TRANSMIT_PIN, 1)
time.sleep(extended_delay)
for i in down_1:
if i == '1':
GPIO.output(TRANSMIT_PIN, 1)
time.sleep(short_delay)
GPIO.output(TRANSMIT_PIN, 0)
time.sleep(long_delay)
print " 1 sent"
elif i == '0':
GPIO.output(TRANSMIT_PIN, 1)
time.sleep(long_delay)
GPIO.output(TRANSMIT_PIN, 0)
time.sleep(short_delay)
print " 0 sent"
else:
continue
GPIO.output(TRANSMIT_PIN, 0)
time.sleep(extended_delay)
print " extended delay sent"
print "out of for loop down_1"
time.sleep(half_code_delay)
print "adding half code delay"
for t in range(NUM_ATTEMPTS):
print "entering for %s on %s" % (t, NUM_ATTEMPTS)
GPIO.output(TRANSMIT_PIN, 1)
time.sleep(extended_delay)
for i in down_2:
if i == '1':
GPIO.output(TRANSMIT_PIN, 1)
time.sleep(short_delay)
GPIO.output(TRANSMIT_PIN, 0)
time.sleep(long_delay)
print " 1 sent"
elif i == '0':
GPIO.output(TRANSMIT_PIN, 1)
time.sleep(long_delay)
GPIO.output(TRANSMIT_PIN, 0)
time.sleep(short_delay)
print " 0 sent"
else:
continue
GPIO.output(TRANSMIT_PIN, 0)
time.sleep(extended_delay)
print " extended delay sent"
print "out of for loop down_2"
print "out of if down"
# END DOWN COMMAND
# STOP COMMAND
if code is stop or (code < 100 and code > 0):
print "stopping"
for t in range(NUM_ATTEMPTS):
print "entering for %s on %s" % (t, NUM_ATTEMPTS)
GPIO.output(TRANSMIT_PIN, 1)
time.sleep(extended_delay)
for i in stop_1:
if i == '1':
GPIO.output(TRANSMIT_PIN, 1)
time.sleep(short_delay)
GPIO.output(TRANSMIT_PIN, 0)
time.sleep(long_delay)
print " 1 sent"
elif i == '0':
GPIO.output(TRANSMIT_PIN, 1)
time.sleep(long_delay)
GPIO.output(TRANSMIT_PIN, 0)
time.sleep(short_delay)
print " 0 sent"
else:
continue
GPIO.output(TRANSMIT_PIN, 0)
time.sleep(extended_delay)
print " extended delay sent"
print "out of for loop stop_1"
# time.sleep(half_code_delay)
# print "adding half code delay"
# for t in range(NUM_ATTEMPTS):
# print "entering for %s on %s" % (t, NUM_ATTEMPTS)
# GPIO.output(TRANSMIT_PIN, 1)
# time.sleep(extended_delay)
# for i in stop_2:
# if i == '1':
# GPIO.output(TRANSMIT_PIN, 1)
# time.sleep(short_delay)
# GPIO.output(TRANSMIT_PIN, 0)
# time.sleep(long_delay)
# print " 1 sent"
# elif i == '0':
# GPIO.output(TRANSMIT_PIN, 1)
# time.sleep(long_delay)
# GPIO.output(TRANSMIT_PIN, 0)
# time.sleep(short_delay)
# print " 0 sent"
# else:
# continue
# GPIO.output(TRANSMIT_PIN, 0)
# time.sleep(extended_delay)
# print " extended delay sent"
# print "out of for loop stop_2"
print "out of if stop"
# END STOP COMMAND
GPIO.output(TRANSMIT_PIN, 0)
time.sleep(half_code_delay)
GPIO.cleanup()
if __name__ == '__main__':
for argument in sys.argv[1:]:
exec('transmit_code(' + str(argument) + ')')