gist: d16e8c31ca381317a450e87a671c1b36, 2017-04-16 20:23:05Z
from gpiozero.pins.rpigpio import RPiGPIOPin
from gpiozero import Button
rows = [12, 16, 20, 21]
cols = [4, 17, 27, 22]
rowPins = []
colPins = []
bounces = {}
for row in rows:
pin = RPiGPIOPin(row)
pin.bounce = 5
rowPins.append(pin)
bounces[pin.number] = {}
for col in cols:
pin = RPiGPIOPin(col)
pin.bounce = 5
colPins.append(pin)
for row in rowPins:
for col in colPins:
bounces[row.number][col.number] = 0
def hookswitchChange():
print("Button Activated")
hookswitch = Button(2)
hookswitch.when_activated = hookswitchChange
hookswitch.when_deactivated = hookswitchChange
print "starting loop"
while True:
for row in rowPins:
# set row pin high
row.output_with_state(True)
for col in colPins:
# read col pin
col.input_with_pull('down')
status = col.state
if col.state == 1:
print "{0}/{1} - {2}".format(row, col, status)
bounces[row.number][col.number] += 2
row.output_with_state(False)
for row, cols in bounces.items():
for col, status in cols.items():
if status > 5:
print "{0}/{1} - {2}".format(row, col, status)
bounces[row][col] -= 1