generated from pimoroni/boilerplate-micropython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b4d1546
commit 21ccff0
Showing
4 changed files
with
145 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,40 @@ | ||
import sys | ||
import time | ||
|
||
from machine import I2C | ||
|
||
from qwstpad import QwSTPad | ||
from qwstpad import ADDRESSES, QwSTPad | ||
|
||
""" | ||
How to read all of the buttons on QwSTPad | ||
""" | ||
|
||
# Constants | ||
SLEEP = 0.1 # The time between each reading of the buttons | ||
I2C_PINS = {"id": 0, "sda": 4, "scl": 5} # The I2C pins the QwSTPad is connected to | ||
I2C_ADDRESS = ADDRESSES[0] # The I2C address of the connected QwSTPad | ||
SLEEP = 0.1 # The time between each reading of the buttons | ||
|
||
# Create the I2C instance and pass that to the QwSTPad | ||
i2c = I2C(0, scl=13, sda=12) | ||
qwstpad = QwSTPad(i2c) | ||
|
||
# Loop forever | ||
while True: | ||
# Read all the buttons from the qwstpad and print them out | ||
buttons = qwstpad.read_buttons() | ||
for key, value in buttons.items(): | ||
print(f"{key} = {value:n}", end=", ") | ||
print() | ||
# Attempt to create the I2C instance and pass that to the QwSTPad | ||
try: | ||
qwstpad = QwSTPad(I2C(**I2C_PINS), I2C_ADDRESS) | ||
except OSError: | ||
print("QwSTPad: Not Connected ... Exiting") | ||
sys.exit() | ||
|
||
time.sleep(SLEEP) | ||
print("QwSTPad: Connected ... Starting") | ||
|
||
# Wrap the code in a try block, to catch any exceptions (including KeyboardInterrupt) | ||
try: | ||
# Loop forever | ||
while True: | ||
# Read all the buttons from the qwstpad and print them out | ||
buttons = qwstpad.read_buttons() | ||
for key, value in buttons.items(): | ||
print(f"{key} = {value:n}", end=", ") | ||
print() | ||
|
||
time.sleep(SLEEP) | ||
|
||
finally: | ||
qwstpad.clear_leds() # Turn off all four LEDs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters