-
Notifications
You must be signed in to change notification settings - Fork 0
/
buttons.py
37 lines (25 loc) · 881 Bytes
/
buttons.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
#!/usr/bin/env python3
from Adafruit_GPIO import MCP230xx as mcs
from Adafruit_GPIO import GPIO
import time
interupt_pin = 23
i2c_address = 0x20
class Buttons(object):
def __init__(self):
self.buttons = mcs.MCP23008(i2c_address)
for i in range(8):
self.buttons.setup(i, GPIO.IN)
# self.buttons.pullup(i, True)
def add_callback(self, callback):
# Setup interupt
gpio = GPIO.get_platform_gpio()
gpio.setup(interupt_pin, GPIO.IN)
gpio.add_event_detect(interupt_pin, GPIO.FALLING, callback=callback, bouncetime=5)
def get_buttons(self):
return self.buttons.input_pins(range(8))
if __name__ == "__main__":
butts = Buttons()
while True:
print(butts.get_buttons())
time.sleep(1)
#butts.add_callback(lambda x: print(butts.get_buttons()))