-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPi_Remote_IR.py
More file actions
64 lines (51 loc) · 1.46 KB
/
Pi_Remote_IR.py
File metadata and controls
64 lines (51 loc) · 1.46 KB
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
import RPi.GPIO as GPIO
import IRModule
import time
from lib_oled96 import ssd1306
from smbus import SMBus
GPIO.setmode(GPIO.BCM) # choose BCM or BOARD
GPIO.setup(17, GPIO.OUT) # set GPIO24 as an output
GPIO.setup(27, GPIO.OUT)
GPIO.setup(22, GPIO.OUT)
i2cbus = SMBus(1)
oled = ssd1306(i2cbus)
draw = oled.canvas
oled.cls()
oled.display()
current_milli_time = lambda: int(round(time.time() * 1000))
def reset_LEDs():
GPIO.output(17, 0)
GPIO.output(27, 0)
GPIO.output(22, 0)
oled.cls()
return
def remote_callback(code):
if code == 16738455: #Button 0
reset_LEDs()
GPIO.output(17, 1)
draw.text((20, 16), "Button 0", fill=1)
if code == 16724175: #Button 1
reset_LEDs()
GPIO.output(27, 1)
draw.text((20, 16), "Button 1", fill=1)
if code == 16718055: #Button 2
reset_LEDs()
GPIO.output(22, 1)
draw.text((20, 16), "Button 2", fill=1)
oled.display()
print(str(code))
return
irPin = 16
ir = IRModule.IRRemote(callback='DECODE')
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM) # uses numbering outside circles
GPIO.setup(irPin,GPIO.IN) # set irPin to input
GPIO.add_event_detect(irPin,GPIO.BOTH,callback=ir.pWidth)
try:
ir.set_callback(remote_callback)
while True:
time.sleep(1)
except KeyboardInterrupt: # trap a CTRL+C keyboard interrupt
print('Removing callback and cleaning up GPIO')
ir.remove_callback()
GPIO.cleanup()