Skip to content

Commit a7d3802

Browse files
authored
Merge pull request #206 from pimoroni/helgibbons-patch-1
Update buttons.py
2 parents 86004c1 + de5648c commit a7d3802

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

examples/7color/buttons.py

+16-6
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,30 @@
44
import gpiodevice
55
from gpiod.line import Bias, Direction, Edge
66

7-
print("""buttons.py - Detect which button has been pressed
7+
print(
8+
"""buttons.py - Detect which button has been pressed
89
910
This example should demonstrate how to:
1011
1. set up gpiod to read buttons,
1112
2. determine which button has been pressed
1213
1314
Press Ctrl+C to exit!
1415
15-
""")
16+
"""
17+
)
1618

1719
# GPIO pins for each button (from top to bottom)
1820
# These will vary depending on platform and the ones
1921
# below should be correct for Raspberry Pi 5.
20-
# Run "gpioinfo" to find out what yours might be
21-
BUTTONS = ["PIN29", "PIN31", "PIN36", "PIN18"]
22+
# Run "gpioinfo" to find out what yours might be.
23+
#
24+
# Raspberry Pi 5 Header pins used by Inky Impression:
25+
# PIN29, PIN31, PIN36, PIN18.
26+
# These header pins correspond to BCM GPIO numbers:
27+
# GPIO05, GPIO06, GPIO16, GPIO24.
28+
# These GPIO numbers are what is used below and not the
29+
# header pin numbers.
30+
BUTTONS = [5, 6, 16, 24]
2231

2332
# These correspond to buttons A, B, C and D respectively
2433
LABELS = ["A", "B", "C", "D"]
@@ -39,13 +48,14 @@
3948
# Request the lines, *whew*
4049
request = chip.request_lines(consumer="inky7-buttons", config=line_config)
4150

51+
4252
# "handle_button" will be called every time a button is pressed
4353
# It receives one argument: the associated gpiod event object.
4454
def handle_button(event):
4555
index = OFFSETS.index(event.line_offset)
46-
pin = BUTTONS[index]
56+
gpio_number = BUTTONS[index]
4757
label = LABELS[index]
48-
print(f"Button press detected on pin: {pin} label: {label}")
58+
print(f"Button press detected on GPIO #{gpio_number} label: {label}")
4959

5060

5161
while True:

0 commit comments

Comments
 (0)