Skip to content

Commit b68efc3

Browse files
authored
Merge branch 'master' into master
2 parents b3835a7 + be1ef3a commit b68efc3

File tree

67 files changed

+9697
-90
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+9697
-90
lines changed

Adafruit_pIRKey/NEC_keyboard_example.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
import adafruit_dotstar
1111
import pulseio
1212
import board
13+
import usb_hid
1314

1415
led = adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1)
1516

1617
# The keyboard object!
1718
time.sleep(1) # Sleep for a bit to avoid a race condition on some systems
18-
keyboard = Keyboard()
19+
keyboard = Keyboard(usb_hid.devices)
1920
keyboard_layout = KeyboardLayoutUS(keyboard) # We're in the US :)
2021

2122
# our infrared pulse decoder helpers

Adafruit_pIRKey/raw_code_keyboard/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
import adafruit_dotstar
99
import adafruit_irremote
1010
import time
11+
import usb_hid
1112

1213
# The keyboard object!
1314
time.sleep(1) # Sleep for a bit to avoid a race condition on some systems
14-
keyboard = Keyboard()
15+
keyboard = Keyboard(usb_hid.devices)
1516
keyboard_layout = KeyboardLayoutUS(keyboard) # We're in the US :)
1617

1718
led = adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1)

Arcade_Button_Control_Box/Arcade_Button_Control_Box.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from adafruit_hid.keyboard import Keyboard
55
from adafruit_hid.keycode import Keycode
66
import board
7+
import usb_hid
78

89
# A simple neat keyboard demo in circuitpython
910

@@ -16,7 +17,7 @@
1617
controlkey = Keycode.LEFT_CONTROL
1718

1819
# the keyboard object!
19-
kbd = Keyboard()
20+
kbd = Keyboard(usb_hid.devices)
2021
# our array of button objects
2122
buttons = []
2223
leds = []

AutoSunglasses/code.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414

1515
import time
1616
import board
17-
import simpleio
17+
import pulseio
1818
from adafruit_circuitplayground.express import cpx
19+
from adafruit_motor import servo
1920

20-
servo = simpleio.Servo(board.A1)
21+
pwm = pulseio.PWMOut(board.A1, duty_cycle=2 ** 15, frequency=50)
22+
my_servo = servo.Servo(pwm)
2123

2224
cpx.pixels.fill((0, 0, 0))
23-
servo.angle = 90
25+
my_servo.angle = 90
2426

2527
while True:
2628
light_level = cpx.light
@@ -30,8 +32,8 @@
3032
else:
3133
cpx.pixels.fill((0, 0, 0))
3234
if light_level < 200:
33-
servo.angle = 90
35+
my_servo.angle = 90
3436
else:
35-
servo.angle = 0
37+
my_servo.angle = 0
3638

3739
time.sleep(0.25)

CPB_ANCS/code.py

Lines changed: 6 additions & 6 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
@@ -34,7 +34,7 @@
3434
"com.apple.mobilephone": "/ancs_phone.bmp"
3535
}
3636

37-
BLACKLIST = []
37+
BLOCKLIST = []
3838
DELAY_AFTER_PRESS = 15
3939
DEBOUNCE = 0.1
4040
DIM_TIMEOUT = 20 # Amount of timeout to turn off backlight
@@ -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)
@@ -123,7 +123,7 @@ def wrap_in_tilegrid(open_file):
123123
current_notifications = notification_service.active_notifications
124124
for notif_id in current_notifications:
125125
notification = current_notifications[notif_id]
126-
if notification.app_id not in APP_ICONS or notification.app_id in BLACKLIST:
126+
if notification.app_id not in APP_ICONS or notification.app_id in BLOCKLIST:
127127
continue
128128
all_ids.append(notif_id)
129129

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
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Magic Light Bulb remote color mixer
2+
# Sends RGB color values, read from three faders on CPB to the bulb
3+
# https://www.magiclightbulbs.com/collections/bluetooth-bulbs
4+
5+
import adafruit_ble
6+
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
7+
from adafruit_ble_magic_light import MagicLightService
8+
import _bleio
9+
import board
10+
from analogio import AnalogIn
11+
from adafruit_circuitplayground import cp
12+
13+
14+
def find_connection():
15+
for connection in radio.connections:
16+
if MagicLightService not in connection: # Filter services
17+
continue
18+
return connection, connection[MagicLightService]
19+
return None, None
20+
21+
radio = adafruit_ble.BLERadio()
22+
23+
24+
def scale(value):
25+
# Scale a value from 0-65535 (AnalogIn range) to 0-255 (RGB range)
26+
return int(value / 65535 * 255)
27+
a4 = AnalogIn(board.A4) # red slider
28+
a5 = AnalogIn(board.A5) # green slider
29+
a6 = AnalogIn(board.A6) # blue slider
30+
31+
cp.pixels.brightness = 0.1
32+
dimmer = 1.0
33+
34+
active_connection, bulb = find_connection() # In case already connected
35+
36+
while True:
37+
if not active_connection: # There's no connection, so let's scan for one
38+
cp.pixels[0] = (60, 40, 0) # set CPB NeoPixel 0 to yellow while searching
39+
print("Scanning for Magic Light...")
40+
# Scan and filter for advertisements with ProvideServicesAdvertiesment type
41+
for advertisement in radio.start_scan(ProvideServicesAdvertisement):
42+
# Filter further for advertisements with MagicLightService
43+
if MagicLightService in advertisement.services:
44+
active_connection = radio.connect(advertisement)
45+
print("Connected to Magic Light")
46+
cp.pixels[0] = (0, 0, 255) # Set NeoPixel 0 to blue when connected
47+
# Play a happy tone
48+
cp.play_tone(440, 0.1)
49+
cp.play_tone(880, 0.1)
50+
print("Adjust slide potentiometers to mix RGB colors")
51+
try:
52+
bulb = active_connection[MagicLightService]
53+
except _bleio.ConnectionError:
54+
print("disconnected")
55+
continue
56+
break
57+
radio.stop_scan() # Now that we're connected, stop scanning
58+
59+
while active_connection.connected: # Connected, now we can set attrs to change colors
60+
# Toggle slide switch to go to half or full brightness
61+
if cp.switch:
62+
cp.red_led = True
63+
dimmer = 0.5
64+
else:
65+
cp.red_led = False
66+
dimmer = 1.0
67+
68+
# Press the 'A' button to momentarily black the bulb
69+
if cp.button_a:
70+
dimmer = 0.0
71+
72+
r = scale(a4.value * dimmer)
73+
g = scale(a5.value * dimmer)
74+
b = scale(a6.value * dimmer)
75+
76+
# Press the 'B' button to momentarily white the bulb
77+
if cp.button_b:
78+
r, g, b = (255, 255, 255)
79+
80+
color = (r, g, b)
81+
82+
try:
83+
bulb[0] = color # Send color to bulb's color characteristic
84+
except _bleio.ConnectionError:
85+
print("disconnected")
86+
continue
87+
cp.pixels[2] = (r, 0, 0)
88+
cp.pixels[3] = (0, g, 0)
89+
cp.pixels[4] = (0, 0, b)
90+
cp.pixels[7] = (color)
91+
92+
active_connection = None # Not connected, start scanning again
93+
cp.pixels[0] = (60, 40, 0)

0 commit comments

Comments
 (0)