-
Notifications
You must be signed in to change notification settings - Fork 0
/
TX.py
46 lines (40 loc) · 1.23 KB
/
TX.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
import time
import sys
import RPi.GPIO as GPIO
sync_length = 0.00246
#53 bit long code
open_code = '0101010101010101010101010101010101010101010101010101'
pulse_length = 0.000410
attempt_delay = 0.01
NUM_ATTEMPTS = 4
TRANSMIT_PIN = 17
def transmit_code(code):
'''Transmit a chosen code string using the GPIO transmitter'''
for t in range(NUM_ATTEMPTS):
GPIO.output(TRANSMIT_PIN, 1)
time.sleep(sync_length)
for i in code:
GPIO.output(TRANSMIT_PIN, 0)
time.sleep(pulse_length)
if i == '1':
GPIO.output(TRANSMIT_PIN, 1)
time.sleep(pulse_length)
elif i == '0':
GPIO.output(TRANSMIT_PIN, 0)
time.sleep(pulse_length)
else:
continue
GPIO.output(TRANSMIT_PIN, 1)
time.sleep(pulse_length)
GPIO.output(TRANSMIT_PIN, 0)
time.sleep(attempt_delay)
try:
if __name__ == '__main__':
GPIO.setmode(GPIO.BCM)
GPIO.setup(TRANSMIT_PIN, GPIO.OUT)
for argument in sys.argv[1:]:
exec('transmit_code(' + str(argument) + ')')
except:
print "Error"
finally:
GPIO.cleanup()