Skip to content

Commit

Permalink
Merge pull request #95 from kattni/arcade-qt-example
Browse files Browse the repository at this point in the history
Adding Arcade QT examples.
  • Loading branch information
ladyada committed Feb 2, 2022
2 parents d3c51b7 + 891efab commit c89c868
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
41 changes: 41 additions & 0 deletions examples/seesaw_arcade_qt_multi_board.py
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
46 changes: 46 additions & 0 deletions examples/seesaw_arcade_qt_simpletest.py
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)

0 comments on commit c89c868

Please sign in to comment.