2021-05-13 14:30:18 +00:00
|
|
|
import time
|
2021-05-18 10:18:41 +00:00
|
|
|
from pimoroni_i2c import PimoroniI2C
|
2021-05-13 14:30:18 +00:00
|
|
|
from breakout_ioexpander import BreakoutIOExpander
|
|
|
|
|
2021-05-18 10:18:41 +00:00
|
|
|
PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5}
|
|
|
|
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21}
|
|
|
|
|
2021-05-13 14:30:18 +00:00
|
|
|
ioe_button_pin = 14
|
|
|
|
|
2021-05-18 10:18:41 +00:00
|
|
|
i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)
|
|
|
|
ioe = BreakoutIOExpander(i2c, address=0x18)
|
2021-05-13 14:30:18 +00:00
|
|
|
|
|
|
|
ioe.set_mode(ioe_button_pin, BreakoutIOExpander.PIN_IN_PU)
|
|
|
|
|
|
|
|
last_state = True
|
|
|
|
|
|
|
|
while True:
|
|
|
|
state = ioe.input(ioe_button_pin)
|
2021-05-13 14:38:00 +00:00
|
|
|
if state is not last_state:
|
|
|
|
if state:
|
2021-05-13 14:30:18 +00:00
|
|
|
print("Button has been released")
|
|
|
|
else:
|
|
|
|
print("Button has been pressed")
|
|
|
|
last_state = state
|
|
|
|
|
|
|
|
time.sleep(0.02)
|