-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathirReceive.py
56 lines (41 loc) · 1.08 KB
/
irReceive.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
import RPi.GPIO as GPIO
import math
import os
from datetime import datetime
from time import sleep
INPUT_WIRE = 26
GPIO.setmode(GPIO.BOARD)
GPIO.setup(INPUT_WIRE, GPIO.IN)
while True:
value = 1
while value:
value = GPIO.input(INPUT_WIRE)
# Grab the start time of the command
startTime = datetime.now()
# Used to buffer the command pulses
command = []
# The end of the "command" happens when we read more than
# a certain number of 1s (1 is off for my IR receiver)
numOnes = 0
# Used to keep track of transitions from 1 to 0
previousVal = 0
while True:
if value != previousVal:
now = datetime.now()
pulseLength = now - startTime
startTime = now
command.append((previousVal, pulseLength.microseconds))
if value:
numOnes = numOnes + 1
else:
numOnes = 0
# 10000 is arbitrary, adjust as necessary
if numOnes > 10000:
break
previousVal = value
value = GPIO.input(INPUT_WIRE)
print "----------Start----------"
for (val, pulse) in command:
print val, pulse
print "-----------End-----------\n"
print "Size of array is " + str(len(command))