-
Notifications
You must be signed in to change notification settings - Fork 5
/
test_gpio_input.py
executable file
·66 lines (53 loc) · 1.97 KB
/
test_gpio_input.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
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python3
# Copyright (c) 2019 Jarret Dyrbye
# Distributed under the MIT software license, see the accompanying
# file LICENSE or http://www.opensource.org/licenses/mit-license.php
import RPi.GPIO as GPIO
from waveshare.epaper import EPaper
from lib.invoicedisplay import InvoiceDisplay
from lib.selections import SELECTIONS
import time
# the order of buttons to GPIO pin connection on my breadboard. YMMV
BUTTON_1 = 16
BUTTON_2 = 15
BUTTON_3 = 11
BUTTON_4 = 12
MAPPING = {BUTTON_1: SELECTIONS[0],
BUTTON_2: SELECTIONS[1],
BUTTON_3: SELECTIONS[2],
BUTTON_4: SELECTIONS[3],
}
class ButtonDrive(object):
def __init__(self):
GPIO.setmode(GPIO.BOARD)
GPIO.setup(BUTTON_1, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(BUTTON_2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(BUTTON_3, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(BUTTON_4, GPIO.IN, pull_up_down=GPIO.PUD_UP)
self.display = InvoiceDisplay(EPaper(), mode=None)
self.drawing = False
def button(self, button_no):
print("pressed: %d" % button_no)
if self.drawing:
print("drawing, skipping")
return
print("start draw")
self.drawing = True
selection = MAPPING[button_no]
self.display.draw_selection(MAPPING[button_no])
self.drawing = False
print("draw finished")
if __name__ == '__main__':
bd = ButtonDrive()
GPIO.add_event_detect(BUTTON_1, GPIO.FALLING, callback=bd.button,
bouncetime=200)
GPIO.add_event_detect(BUTTON_2, GPIO.FALLING, callback=bd.button,
bouncetime=200)
GPIO.add_event_detect(BUTTON_3, GPIO.FALLING, callback=bd.button,
bouncetime=200)
GPIO.add_event_detect(BUTTON_4, GPIO.FALLING, callback=bd.button,
bouncetime=200)
print("start")
while True:
time.sleep(0.01)
GPIO.cleanup()