-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from kattni/arcade-qt-example
Adding Arcade QT examples.
- Loading branch information
Showing
2 changed files
with
87 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# SPDX-FileCopyrightText: 2022 Kattni Rembor for Adafruit Industries | ||
# SPDX-License-Identifier: MIT | ||
"""Arcade QT example for multiple boards that turns on button LED when button is pressed""" | ||
import board | ||
import digitalio | ||
from adafruit_seesaw.seesaw import Seesaw | ||
from adafruit_seesaw.digitalio import DigitalIO | ||
|
||
# For most boards. | ||
i2c = board.I2C() | ||
|
||
# For the QT Py RP2040, QT Py ESP32-S2, other boards that have SCL1/SDA1 as the STEMMA QT port. | ||
# import busio | ||
# i2c = busio.I2C(board.SCL1, board.SDA1) | ||
arcade_qt_one = Seesaw(i2c, addr=0x3A) | ||
arcade_qt_two = Seesaw(i2c, addr=0x3B) | ||
|
||
arcade_qts = (arcade_qt_one, arcade_qt_two) | ||
|
||
# Button pins in order (1, 2, 3, 4) | ||
button_pins = (18, 19, 20, 2) | ||
buttons = [] | ||
for arcade_qt in arcade_qts: | ||
for button_pin in button_pins: | ||
button = DigitalIO(arcade_qt, button_pin) | ||
button.direction = digitalio.Direction.INPUT | ||
button.pull = digitalio.Pull.UP | ||
buttons.append(button) | ||
|
||
# LED pins in order (1, 2, 3, 4) | ||
led_pins = (12, 13, 0, 1) | ||
leds = [] | ||
for arcade_qt in arcade_qts: | ||
for led_pin in led_pins: | ||
led = DigitalIO(arcade_qt, led_pin) | ||
led.direction = digitalio.Direction.OUTPUT | ||
leds.append(led) | ||
|
||
while True: | ||
for led_number, button in enumerate(buttons): | ||
leds[led_number].value = not button.value |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# SPDX-FileCopyrightText: 2022 Kattni Rembor for Adafruit Industries | ||
# SPDX-License-Identifier: MIT | ||
"""Arcade QT example that pulses the button LED on button press""" | ||
import time | ||
import board | ||
import digitalio | ||
from adafruit_seesaw.seesaw import Seesaw | ||
from adafruit_seesaw.digitalio import DigitalIO | ||
from adafruit_seesaw.pwmout import PWMOut | ||
|
||
# The delay on the PWM cycles. Increase to slow down the LED pulsing, decrease to speed it up. | ||
delay = 0.01 | ||
|
||
# For most boards. | ||
i2c = board.I2C() | ||
|
||
# For the QT Py RP2040, QT Py ESP32-S2, other boards that have SCL1/SDA1 as the STEMMA QT port. | ||
# import busio | ||
# i2c = busio.I2C(board.SCL1, board.SDA1) | ||
arcade_qt = Seesaw(i2c, addr=0x3A) | ||
|
||
# Button pins in order (1, 2, 3, 4) | ||
button_pins = (18, 19, 20, 2) | ||
buttons = [] | ||
for button_pin in button_pins: | ||
button = DigitalIO(arcade_qt, button_pin) | ||
button.direction = digitalio.Direction.INPUT | ||
button.pull = digitalio.Pull.UP | ||
buttons.append(button) | ||
|
||
# LED pins in order (1, 2, 3, 4) | ||
led_pins = (12, 13, 0, 1) | ||
leds = [] | ||
for led_pin in led_pins: | ||
led = PWMOut(arcade_qt, led_pin) | ||
leds.append(led) | ||
|
||
while True: | ||
for led_number, button in enumerate(buttons): | ||
if not button.value: | ||
for cycle in range(0, 65535, 8000): | ||
leds[led_number].duty_cycle = cycle | ||
time.sleep(delay) | ||
for cycle in range(65534, 0, -8000): | ||
leds[led_number].duty_cycle = cycle | ||
time.sleep(delay) |