Skip to content

Commit e7aaafd

Browse files
authored
Merge branch 'adafruit:main' into claycooper-group-prop-deprecation-fix
2 parents 39dc5d7 + 876e647 commit e7aaafd

File tree

5 files changed

+176
-24
lines changed

5 files changed

+176
-24
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2022 Dan Halbert for Adafruit Industries
2+
# SPDX-FileCopyrightText: Copyright (c) 2022 Kattni Rembor for Adafruit Industries
3+
#
4+
# SPDX-License-Identifier: MIT
5+
"""
6+
CircuitPython asyncio example for two NeoPixel rings and one button.
7+
REMOVE THIS LINE AND THE REST OF THIS DOCSTRING BEFORE SUBMITTING TO LEARN
8+
THERE ARE TWO POSSIBLE THINGS IN THE CODE TO UPDATE.
9+
10+
One: Update BUTTON to the pin that matches the pin to which the button is connected.
11+
12+
For example, on the QT Py RP2040, you would leave it as BUTTON to use the built-in Boot button.
13+
On the FunHouse, you would update BUTTON to BUTTON_UP to use the built-in up button.
14+
On the Feather M4 Express, you would wire the external button to A0, and update BUTTON to A0.
15+
16+
Two: THIS IS ONLY NECESSARY IF THE BUILT-IN BUTTON IS ACTIVE HIGH. For example the built-in
17+
buttons on the Circuit Playground Bluefruit and the MagTag are active high.
18+
If your button is ACTIVE HIGH, under "async def monitor_button(button, animation_controls)",
19+
update the following line of code:
20+
with keypad.Keys((button,), value_when_pressed=False, pull=True) as key:
21+
To the following:
22+
with keypad.Keys((button,), value_when_pressed=True, pull=True) as key:
23+
"""
24+
import asyncio
25+
import board
26+
import neopixel
27+
import keypad
28+
from rainbowio import colorwheel
29+
30+
button_pin = board.BUTTON # The pin the button is connected to.
31+
num_pixels = 16 # The number of NeoPixels on a single ring.
32+
brightness = 0.2 # The LED brightness.
33+
34+
# Set up NeoPixel rings.
35+
ring_one = neopixel.NeoPixel(board.A1, num_pixels, brightness=brightness, auto_write=False)
36+
ring_two = neopixel.NeoPixel(board.A2, num_pixels, brightness=brightness, auto_write=False)
37+
38+
39+
class AnimationControls:
40+
"""The controls to allow you to vary the rainbow and blink animations."""
41+
def __init__(self):
42+
self.reverse = False
43+
self.wait = 0.0
44+
self.delay = 0.5
45+
46+
47+
async def rainbow_cycle(animation_controls):
48+
"""Rainbow cycle animation on ring one."""
49+
while True:
50+
for j in range(255, -1, -1) if animation_controls.reverse else range(0, 256, 1):
51+
for i in range(num_pixels):
52+
rc_index = (i * 256 // num_pixels) + j
53+
ring_one[i] = colorwheel(rc_index & 255)
54+
ring_one.show()
55+
await asyncio.sleep(animation_controls.wait)
56+
57+
58+
async def blink(animation_controls):
59+
"""Blink animation on ring two."""
60+
while True:
61+
ring_two.fill((0, 0, 255))
62+
ring_two.show()
63+
await asyncio.sleep(animation_controls.delay)
64+
ring_two.fill((0, 0, 0))
65+
ring_two.show()
66+
await asyncio.sleep(animation_controls.delay)
67+
await asyncio.sleep(animation_controls.wait)
68+
69+
70+
async def monitor_button(button, animation_controls):
71+
"""Monitor button that reverses rainbow direction and changes blink speed.
72+
Assume button is active low.
73+
"""
74+
with keypad.Keys((button,), value_when_pressed=False, pull=True) as key:
75+
while True:
76+
key_event = key.events.get()
77+
if key_event:
78+
if key_event.pressed:
79+
animation_controls.reverse = True
80+
animation_controls.delay = 0.1
81+
elif key_event.released:
82+
animation_controls.reverse = False
83+
animation_controls.delay = 0.5
84+
# Let another task run.
85+
await asyncio.sleep(0)
86+
87+
88+
async def main():
89+
animation_controls = AnimationControls()
90+
buttons_task = asyncio.create_task(monitor_button(button_pin, animation_controls))
91+
animation_task = asyncio.create_task(rainbow_cycle(animation_controls))
92+
blink_task = asyncio.create_task(blink(animation_controls))
93+
94+
# This will run forever, because no tasks ever finish.
95+
await asyncio.gather(buttons_task, animation_task, blink_task)
96+
97+
asyncio.run(main())

FunHouse_Arduino_Demos/selftest/selftest.ino

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#define NUM_DOTSTAR 5
1212
#define BG_COLOR ST77XX_BLACK
13+
#define ST77XX_GREY 0x8410 // Colors are in RGB565 format
1314

1415
// display!
1516
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RESET);
@@ -125,23 +126,23 @@ void loop() {
125126
tft.setTextColor(ST77XX_YELLOW);
126127
tft.print("Buttons: ");
127128
if (! digitalRead(BUTTON_DOWN)) {
128-
tft.setTextColor(0x808080);
129+
tft.setTextColor(ST77XX_GREY);
129130
} else {
130131
Serial.println("DOWN pressed");
131132
tft.setTextColor(ST77XX_WHITE);
132133
}
133134
tft.print("DOWN ");
134135

135136
if (! digitalRead(BUTTON_SELECT)) {
136-
tft.setTextColor(0x808080);
137+
tft.setTextColor(ST77XX_GREY);
137138
} else {
138139
Serial.println("SELECT pressed");
139140
tft.setTextColor(ST77XX_WHITE);
140141
}
141142
tft.print("SEL ");
142143

143144
if (! digitalRead(BUTTON_UP)) {
144-
tft.setTextColor(0x808080);
145+
tft.setTextColor(ST77XX_GREY);
145146
} else {
146147
Serial.println("UP pressed");
147148
tft.setTextColor(ST77XX_WHITE);
@@ -156,7 +157,7 @@ void loop() {
156157
tft.print("Captouch 6: ");
157158
touchread = touchRead(6);
158159
if (touchread < 10000 ) {
159-
tft.setTextColor(0x808080, BG_COLOR);
160+
tft.setTextColor(ST77XX_GREY, BG_COLOR);
160161
} else {
161162
tft.setTextColor(ST77XX_WHITE, BG_COLOR);
162163
}
@@ -169,7 +170,7 @@ void loop() {
169170
tft.print("Captouch 7: ");
170171
touchread = touchRead(7);
171172
if (touchread < 20000 ) {
172-
tft.setTextColor(0x808080, BG_COLOR);
173+
tft.setTextColor(ST77XX_GREY, BG_COLOR);
173174
} else {
174175
tft.setTextColor(ST77XX_WHITE, BG_COLOR);
175176
}
@@ -183,7 +184,7 @@ void loop() {
183184
tft.print("Captouch 8: ");
184185
touchread = touchRead(8);
185186
if (touchread < 20000 ) {
186-
tft.setTextColor(0x808080, BG_COLOR);
187+
tft.setTextColor(ST77XX_GREY, BG_COLOR);
187188
} else {
188189
tft.setTextColor(ST77XX_WHITE, BG_COLOR);
189190
}
@@ -248,10 +249,10 @@ void loop() {
248249
/************************** Beep! */
249250
if (digitalRead(BUTTON_SELECT)) {
250251
Serial.println("** Beep! ***");
251-
tone(SPEAKER, 988, 100); // tone1 - B5
252-
tone(SPEAKER, 1319, 200); // tone2 - E6
252+
fhtone(SPEAKER, 988.0, 100.0); // tone1 - B5
253+
fhtone(SPEAKER, 1319.0, 200.0); // tone2 - E6
253254
delay(100);
254-
//tone(SPEAKER, 2000, 100);
255+
//fhtone(SPEAKER, 2000.0, 100.0);
255256
}
256257

257258
/************************** LEDs */
@@ -269,7 +270,7 @@ void loop() {
269270
}
270271

271272

272-
void tone(uint8_t pin, float frequency, float duration) {
273+
void fhtone(uint8_t pin, float frequency, float duration) {
273274
ledcSetup(1, frequency, 8);
274275
ledcAttachPin(pin, 1);
275276
ledcWrite(1, 128);

FunHouse_Arduino_Demos/shipping_demo/shipping_demo.ino

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
#include <Adafruit_AHTX0.h>
1010

1111
#define NUM_DOTSTAR 5
12-
#define BG_COLOR ST77XX_BLACK
12+
#define BG_COLOR ST77XX_BLACK // Set background to black
13+
#define ST77XX_GREY 0x8410 // define mid-grey in RGB565
1314

1415
// display!
1516
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RESET);
@@ -124,23 +125,23 @@ void loop() {
124125
tft.setTextColor(ST77XX_YELLOW);
125126
tft.print("Buttons: ");
126127
if (! digitalRead(BUTTON_DOWN)) {
127-
tft.setTextColor(0x808080);
128+
tft.setTextColor(ST77XX_GREY);
128129
} else {
129130
Serial.println("DOWN pressed");
130131
tft.setTextColor(ST77XX_WHITE);
131132
}
132133
tft.print("DOWN ");
133134

134135
if (! digitalRead(BUTTON_SELECT)) {
135-
tft.setTextColor(0x808080);
136+
tft.setTextColor(ST77XX_GREY);
136137
} else {
137138
Serial.println("SELECT pressed");
138139
tft.setTextColor(ST77XX_WHITE);
139140
}
140141
tft.print("SEL ");
141142

142143
if (! digitalRead(BUTTON_UP)) {
143-
tft.setTextColor(0x808080);
144+
tft.setTextColor(ST77XX_GREY);
144145
} else {
145146
Serial.println("UP pressed");
146147
tft.setTextColor(ST77XX_WHITE);
@@ -155,7 +156,7 @@ void loop() {
155156
tft.print("Captouch 6: ");
156157
touchread = touchRead(6);
157158
if (touchread < 10000 ) {
158-
tft.setTextColor(0x808080, BG_COLOR);
159+
tft.setTextColor(ST77XX_GREY, BG_COLOR);
159160
} else {
160161
tft.setTextColor(ST77XX_WHITE, BG_COLOR);
161162
}
@@ -168,7 +169,7 @@ void loop() {
168169
tft.print("Captouch 7: ");
169170
touchread = touchRead(7);
170171
if (touchread < 20000 ) {
171-
tft.setTextColor(0x808080, BG_COLOR);
172+
tft.setTextColor(ST77XX_GREY, BG_COLOR);
172173
} else {
173174
tft.setTextColor(ST77XX_WHITE, BG_COLOR);
174175
}
@@ -182,7 +183,7 @@ void loop() {
182183
tft.print("Captouch 8: ");
183184
touchread = touchRead(8);
184185
if (touchread < 20000 ) {
185-
tft.setTextColor(0x808080, BG_COLOR);
186+
tft.setTextColor(ST77XX_GREY, BG_COLOR);
186187
} else {
187188
tft.setTextColor(ST77XX_WHITE, BG_COLOR);
188189
}
@@ -247,10 +248,10 @@ void loop() {
247248
/************************** Beep! */
248249
if (digitalRead(BUTTON_SELECT)) {
249250
Serial.println("** Beep! ***");
250-
tone(SPEAKER, 988, 100); // tone1 - B5
251-
tone(SPEAKER, 1319, 200); // tone2 - E6
251+
fhtone(SPEAKER, 988.0, 100.0); // tone1 - B5
252+
fhtone(SPEAKER, 1319.0, 200.0); // tone2 - E6
252253
delay(100);
253-
//tone(SPEAKER, 2000, 100);
254+
//fhtone(SPEAKER, 2000.0, 100.0);
254255
}
255256

256257
/************************** LEDs */
@@ -268,7 +269,7 @@ void loop() {
268269
}
269270

270271

271-
void tone(uint8_t pin, float frequecy, float duration) {
272+
void fhtone(uint8_t pin, float frequecy, float duration) {
272273
ledcSetup(1, frequecy * 80, 8);
273274
ledcAttachPin(pin, 1);
274275
ledcWrite(1, 128);

MIDI_Foot_Pedal/code.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# SPDX-FileCopyrightText: 2022 Liz Clark for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
import board
5+
import usb_midi
6+
import adafruit_midi
7+
import simpleio
8+
from analogio import AnalogIn
9+
from adafruit_midi.control_change import ControlChange
10+
11+
# midi setup
12+
midi = adafruit_midi.MIDI(
13+
midi_in=usb_midi.ports[0], in_channel=0, midi_out=usb_midi.ports[1], out_channel=0
14+
)
15+
16+
# potentiometer setup
17+
mod_pot = AnalogIn(board.A0)
18+
19+
# function to read analog input
20+
def val(pin):
21+
return pin.value
22+
23+
# variables for last read value
24+
# defaults to 0
25+
# no pitchbend is 8192
26+
mod_val2 = 0
27+
28+
while True:
29+
30+
# uncomment below to print potentiometer values in the REPL
31+
# print("{}".format(mod_pot.value))
32+
33+
# map range of potentiometer input to midi values
34+
mod_val1 = round(simpleio.map_range(val(mod_pot), 41200, 58500, 0, 127))
35+
36+
# if modulation value is updated...
37+
if abs(mod_val1 - mod_val2) > 2:
38+
# update mod_val2
39+
mod_val2 = mod_val1
40+
# create integer
41+
modulation = int(mod_val2)
42+
# create CC message
43+
modWheel = ControlChange(1, modulation)
44+
# send CC message
45+
midi.send(modWheel)

PyPortal_User_Interface/code.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,20 @@ def set_backlight(val):
6464
board.DISPLAY.brightness = val
6565

6666
# Set the Backlight
67-
set_backlight(0.3)
67+
if board.board_id == "pyportal_titano":
68+
# 0.3 brightness does not cause the display to be visible on the Titano
69+
set_backlight(1)
70+
else:
71+
set_backlight(0.3)
6872

6973
# Touchscreen setup
7074
# ------Rotate 270:
71-
screen_width = 240
72-
screen_height = 320
75+
if board.board_id == "pyportal_titano":
76+
screen_width = 320
77+
screen_height = 480
78+
else:
79+
screen_width = 240
80+
screen_height = 320
7381
ts = adafruit_touchscreen.Touchscreen(board.TOUCH_YD, board.TOUCH_YU,
7482
board.TOUCH_XR, board.TOUCH_XL,
7583
calibration=((5200, 59000),

0 commit comments

Comments
 (0)