Skip to content

Commit 1a3d447

Browse files
authored
Merge branch 'master' into cpy5beta0-update-disco-tie
2 parents b9c4b38 + 1e8fe9b commit 1a3d447

File tree

9 files changed

+3322
-4
lines changed

9 files changed

+3322
-4
lines changed

CPB_ANCS/code.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import displayio
1313
import adafruit_ble
1414
from adafruit_ble.advertising.standard import SolicitServicesAdvertisement
15-
from adafruit_ble.services.apple import AppleNotificationService
15+
from adafruit_ble_apple_notification_center import AppleNotificationCenterService
1616
from adafruit_gizmo import tft_gizmo
1717
from audiocore import WaveFile
1818
from audiopwmio import PWMAudioOut as AudioOut
@@ -54,11 +54,11 @@ def play_sound():
5454

5555
def find_connection():
5656
for connection in radio.connections:
57-
if AppleNotificationService not in connection:
57+
if AppleNotificationCenterService not in connection:
5858
continue
5959
if not connection.paired:
6060
connection.pair()
61-
return connection, connection[AppleNotificationService]
61+
return connection, connection[AppleNotificationCenterService]
6262
return None, None
6363

6464
class Dimmer:
@@ -86,7 +86,7 @@ def check_timeout(self):
8686
radio = adafruit_ble.BLERadio()
8787
advertisement = SolicitServicesAdvertisement()
8888
advertisement.complete_name = "CIRCUITPY"
89-
advertisement.solicited_services.append(AppleNotificationService)
89+
advertisement.solicited_services.append(AppleNotificationCenterService)
9090

9191
def wrap_in_tilegrid(open_file):
9292
odb = displayio.OnDiskBitmap(open_file)

CPB_ANCS/print_code.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"""This demo shows the latest notification from a connected Apple device on the REPL and Gizmo"""
2+
import time
3+
import adafruit_ble
4+
from adafruit_ble.advertising.standard import SolicitServicesAdvertisement
5+
from adafruit_ble_apple_notification_center import AppleNotificationCenterService
6+
from adafruit_gizmo import tft_gizmo
7+
8+
# This is a whitelist of apps to show notifications from.
9+
#APPS = ["com.tinyspeck.chatlyio", "com.atebits.Tweetie2"]
10+
APPS = []
11+
12+
DELAY_AFTER_PRESS = 15
13+
DEBOUNCE = 0.1
14+
15+
def find_connection():
16+
for connection in radio.connections:
17+
if AppleNotificationCenterService not in connection:
18+
continue
19+
if not connection.paired:
20+
connection.pair()
21+
return connection, connection[AppleNotificationCenterService]
22+
return None, None
23+
24+
# Start advertising before messing with the display so that we can connect immediately.
25+
radio = adafruit_ble.BLERadio()
26+
advertisement = SolicitServicesAdvertisement()
27+
advertisement.complete_name = "CIRCUITPY"
28+
advertisement.solicited_services.append(AppleNotificationCenterService)
29+
30+
display = tft_gizmo.TFT_Gizmo()
31+
32+
current_notification = None
33+
new_ids = []
34+
displayed_ids = []
35+
active_connection, notification_service = find_connection()
36+
while True:
37+
if not active_connection:
38+
radio.start_advertising(advertisement)
39+
40+
while not active_connection:
41+
print("waiting for connection...")
42+
active_connection, notification_service = find_connection()
43+
time.sleep(0.1)
44+
45+
while active_connection.connected:
46+
current_notifications = notification_service.active_notifications
47+
for notification_id in current_notifications:
48+
if notification_id in displayed_ids:
49+
continue # already seen!
50+
notification = current_notifications[notification_id]
51+
print('-'*36)
52+
category = str(notification).split(" ", 1)[0]
53+
print("Msg #%d - Category %s" % (notification.id, category))
54+
print("From app:", notification.app_id)
55+
if notification.title:
56+
print("Title:", notification.title)
57+
if notification.subtitle:
58+
print("Subtitle:", notification.subtitle)
59+
if notification.message:
60+
print("Message:", notification.message)
61+
displayed_ids.append(id)
62+
active_connection = None
63+
notification_service = None

CPB_NeoPixel_Wooden_Xmas_Tree/code.py

Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
import random
2+
import board
3+
import neopixel
4+
import adafruit_fancyled.adafruit_fancyled as fancy
5+
from adafruit_bluefruit_connect.packet import Packet
6+
from adafruit_bluefruit_connect.button_packet import ButtonPacket
7+
from adafruit_ble import BLERadio
8+
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
9+
from adafruit_ble.services.nordic import UARTService
10+
11+
# setting up # of neopixels
12+
TREE_LEDS = 12
13+
CPX_LEDS = 10
14+
# setting up pins for neopixels
15+
TREE_PIN = board.A1
16+
CPX_PIN = board.D8
17+
18+
# neopixel setup
19+
tree = neopixel.NeoPixel(TREE_PIN, TREE_LEDS, brightness=0.5, auto_write=False)
20+
cpx = neopixel.NeoPixel(CPX_PIN, CPX_LEDS, brightness=0.1, auto_write=False)
21+
22+
# BLE setup
23+
ble = BLERadio()
24+
uart = UARTService()
25+
advertisement = ProvideServicesAdvertisement(uart)
26+
advertising = False
27+
28+
# to turn neopixels off
29+
OFF = (0, 0, 0)
30+
31+
# fancyLED color palettes
32+
33+
fairy_palette = [fancy.CRGB(1.0, 0.0, 0.0),
34+
fancy.CRGB(1.0, 0.5, 0.0),
35+
fancy.CRGB(0.0, 0.5, 0.0),
36+
fancy.CRGB(0.0, 1.0, 1.0),
37+
fancy.CRGB(0.0, 0.0, 1.0),
38+
fancy.CRGB(0.75, 0.0, 1.0)]
39+
40+
merry_palette = [fancy.CRGB(1.0, 0.0, 0.0),
41+
fancy.CRGB(0.0, 1.0, 0.0)]
42+
43+
winter_palette = [fancy.CRGB(0.0, 0.75, 0.0),
44+
fancy.CRGB(0.0, 1.0, 1.0),
45+
fancy.CRGB(0.75, 0.0, 1.0),
46+
fancy.CRGB(1.0, 1.0, 1.0),
47+
fancy.CRGB(0.0, 0.75, 0.0),
48+
fancy.CRGB(0.75, 0.0, 1.0),
49+
fancy.CRGB(0.0, 0.0, 1.0),
50+
fancy.CRGB(0.0, 1.0, 1.0),
51+
fancy.CRGB(1.0, 0.0, 1.0)]
52+
53+
star_palette = [fancy.CRGB(1.0, 0.75, 0.0),
54+
fancy.CRGB(1.0, 1.0, 1.0),
55+
fancy.CRGB(1.0, 0.75, 0.0),
56+
fancy.CRGB(0.75, 0.75, 0.75),
57+
fancy.CRGB(1.0, 0.75, 0.0)]
58+
59+
hanukkah_palette = [fancy.CRGB(0.0, 1.0, 1.0),
60+
fancy.CRGB(0.0, 0.0, 1.0),
61+
fancy.CRGB(1.0, 0.75, 0.0),
62+
fancy.CRGB(0.0, 0.0, 1.0),
63+
fancy.CRGB(1.0, 1.0, 1.0)]
64+
65+
# default offset value
66+
offset = 0
67+
68+
def gimel():
69+
for i in range(TREE_LEDS):
70+
color = fancy.palette_lookup(hanukkah_palette, (offset - i) / 5)
71+
color = fancy.gamma_adjust(color, brightness=0.3)
72+
tree[i] = color.pack()
73+
tree.show()
74+
75+
for i in range(CPX_LEDS):
76+
color = fancy.palette_lookup(hanukkah_palette, (offset - i) / 3)
77+
color = fancy.gamma_adjust(color, brightness=0.3)
78+
cpx[i] = color.pack()
79+
cpx.show()
80+
81+
# neopixel animations
82+
83+
def jazzy():
84+
for i in range(TREE_LEDS):
85+
color = fancy.palette_lookup(fairy_palette, (offset - i) / 4.8)
86+
color = fancy.gamma_adjust(color, brightness=0.3)
87+
tree[i] = color.pack()
88+
tree.show()
89+
90+
for i in range(CPX_LEDS):
91+
color = fancy.palette_lookup(fairy_palette, (offset + i) / 4)
92+
color = fancy.gamma_adjust(color, brightness=0.3)
93+
cpx[i] = color.pack()
94+
cpx.show()
95+
96+
def latkes():
97+
for i in range(TREE_LEDS):
98+
color = fancy.palette_lookup(hanukkah_palette, (offset - 24) / TREE_LEDS)
99+
color = fancy.gamma_adjust(color, brightness=0.3)
100+
tree[i] = color.pack()
101+
tree.show()
102+
103+
for i in range(CPX_LEDS):
104+
color = fancy.palette_lookup(hanukkah_palette, (offset - 20) / CPX_LEDS)
105+
color = fancy.gamma_adjust(color, brightness=0.3)
106+
cpx[i] = color.pack()
107+
cpx.show()
108+
109+
def twinkle():
110+
for i in range(60):
111+
color = fancy.palette_lookup(fairy_palette, offset + i / CPX_LEDS)
112+
color = fancy.gamma_adjust(color, brightness=0.25)
113+
p = random.randint(0, (CPX_LEDS - 1))
114+
cpx[p] = color.pack()
115+
cpx.show()
116+
117+
for i in range(60):
118+
color = fancy.palette_lookup(fairy_palette, offset + i / TREE_LEDS)
119+
color = fancy.gamma_adjust(color, brightness=0.25)
120+
p = random.randint(0, (TREE_LEDS - 1))
121+
tree[p] = color.pack()
122+
tree.show()
123+
124+
def merry():
125+
for i in range(TREE_LEDS):
126+
color = fancy.palette_lookup(merry_palette, (offset + i) / (TREE_LEDS / 2))
127+
color = fancy.gamma_adjust(color, brightness=0.25)
128+
tree[i] = color.pack()
129+
tree.show()
130+
131+
for i in range(60):
132+
color = fancy.palette_lookup(star_palette, (offset + i) / CPX_LEDS)
133+
color = fancy.gamma_adjust(color, brightness=0.25)
134+
p = random.randint(0, (CPX_LEDS - 1))
135+
cpx[p] = color.pack()
136+
cpx.show()
137+
138+
def festive():
139+
for i in range(TREE_LEDS):
140+
color = fancy.palette_lookup(merry_palette, (offset - i) / 2)
141+
color = fancy.gamma_adjust(color, brightness=0.25)
142+
tree[i] = color.pack()
143+
tree.show()
144+
145+
for i in range(CPX_LEDS):
146+
color = fancy.palette_lookup(star_palette, (offset + i) / CPX_LEDS)
147+
color = fancy.gamma_adjust(color, brightness=0.25)
148+
cpx[i] = color.pack()
149+
cpx.show()
150+
151+
def fancy_swirl():
152+
for i in range(TREE_LEDS):
153+
color = fancy.palette_lookup(winter_palette, (offset + i) / TREE_LEDS)
154+
color = fancy.gamma_adjust(color, brightness=0.25)
155+
tree[i] = color.pack()
156+
tree.show()
157+
158+
for i in range(CPX_LEDS):
159+
color = fancy.palette_lookup(star_palette, (offset - i) / CPX_LEDS)
160+
color = fancy.gamma_adjust(color, brightness=0.25)
161+
cpx[i] = color.pack()
162+
cpx.show()
163+
164+
# states for different neopixel displays
165+
fairies = False
166+
feeling_fancy = False
167+
feeling_festive = False
168+
feeling_jazzy = False
169+
feeling_merry = False
170+
frying_latkes = False
171+
rolling_gimel = False
172+
173+
while True:
174+
# states to trigger the different neopixel modes
175+
if fairies:
176+
twinkle()
177+
offset += 0.5
178+
if feeling_fancy:
179+
fancy_swirl()
180+
offset += 0.05
181+
if feeling_festive:
182+
festive()
183+
offset += 0.05
184+
if feeling_jazzy:
185+
jazzy()
186+
offset += 0.08
187+
if feeling_merry:
188+
merry()
189+
offset += 0.12
190+
if frying_latkes:
191+
latkes()
192+
offset += 0.05
193+
if rolling_gimel:
194+
gimel()
195+
offset += 0.05
196+
197+
if not ble.connected and not advertising:
198+
# not connected in the app yet
199+
ble.start_advertising(advertisement)
200+
advertising = True
201+
202+
if ble.connected:
203+
# after connected via app
204+
advertising = False
205+
if uart.in_waiting:
206+
# waiting for input from app
207+
packet = Packet.from_stream(uart)
208+
if isinstance(packet, ButtonPacket):
209+
# if buttons in the app are pressed
210+
if packet.pressed:
211+
# fairies
212+
if packet.button == ButtonPacket.UP:
213+
fairies = True
214+
feeling_fancy = False
215+
feeling_festive = False
216+
feeling_jazzy = False
217+
feeling_merry = False
218+
frying_latkes = False
219+
rolling_gimel = False
220+
# fancy
221+
if packet.button == ButtonPacket.LEFT:
222+
fairies = False
223+
feeling_fancy = True
224+
feeling_festive = False
225+
feeling_jazzy = False
226+
feeling_merry = False
227+
frying_latkes = False
228+
rolling_gimel = False
229+
# festive
230+
if packet.button == ButtonPacket.RIGHT:
231+
fairies = False
232+
feeling_fancy = False
233+
feeling_festive = True
234+
feeling_jazzy = False
235+
feeling_merry = False
236+
frying_latkes = False
237+
rolling_gimel = False
238+
# jazzy
239+
if packet.button == ButtonPacket.DOWN:
240+
fairies = False
241+
feeling_fancy = False
242+
feeling_festive = False
243+
feeling_jazzy = True
244+
feeling_merry = False
245+
frying_latkes = False
246+
rolling_gimel = False
247+
# merry
248+
if packet.button == ButtonPacket.BUTTON_1:
249+
fairies = False
250+
feeling_fancy = False
251+
feeling_festive = False
252+
feeling_jazzy = False
253+
feeling_merry = True
254+
frying_latkes = False
255+
rolling_gimel = False
256+
# latkes
257+
if packet.button == ButtonPacket.BUTTON_2:
258+
fairies = False
259+
feeling_fancy = False
260+
feeling_festive = False
261+
feeling_jazzy = False
262+
feeling_merry = False
263+
frying_latkes = True
264+
rolling_gimel = False
265+
# gimel
266+
if packet.button == ButtonPacket.BUTTON_3:
267+
fairies = False
268+
feeling_fancy = False
269+
feeling_festive = False
270+
feeling_jazzy = False
271+
feeling_merry = False
272+
frying_latkes = False
273+
rolling_gimel = True
274+
# off
275+
if packet.button == ButtonPacket.BUTTON_4:
276+
fairies = False
277+
feeling_fancy = False
278+
feeling_festive = False
279+
feeling_jazzy = False
280+
feeling_merry = False
281+
frying_latkes = False
282+
rolling_gimel = False
283+
cpx.fill(OFF)
284+
tree.fill(OFF)
285+
tree.show()
286+
cpx.show()

GemmaM0_Headband/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## Twinkly Earwarmer Headband Tutorial code
2+
3+
Code to accompany the tutorial Twinkly Earwarmer Headband (using an Adafruit Gemma M0) by Kathy Ceceri
4+
5+
CircuitPython Code by Anne Barela
6+
7+
See this guide at https://learn.adafruit.com/TwinklyEarwarmer/overview
8+
9+
MIT License, please attribute and include this file.
10+
11+
Adafruit expends resources providing open source materials, please support their work by buying products at https://www.adafruit.com

0 commit comments

Comments
 (0)