Skip to content

Commit d37f0ac

Browse files
authored
Merge branch 'master' into master
2 parents 6110f14 + 90c4da8 commit d37f0ac

File tree

30 files changed

+4664
-39
lines changed

30 files changed

+4664
-39
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 = []
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)

CPX_GBoard/arcade_hid.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"""
1414

1515
import board
16+
import usb_hid
1617
from adafruit_hid.keyboard import Keyboard
1718
from adafruit_hid.keycode import Keycode
1819
from digitalio import DigitalInOut, Direction, Pull
@@ -28,7 +29,7 @@
2829
button_b.direction = Direction.INPUT
2930
button_b.pull = Pull.UP
3031

31-
kbd = Keyboard()
32+
kbd = Keyboard(usb_hid.devices)
3233

3334

3435
def touch_a():

CPX_GBoard/touch_hid.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
All text above must be included in any redistribution.
1313
"""
1414

15+
import usb_hid
1516
from adafruit_circuitplayground.express import cpx
1617
from adafruit_hid.keyboard import Keyboard
1718
from adafruit_hid.keycode import Keycode
1819

1920
DOT_DURATION = 0.25
2021
DASH_DURATION = 0.5
2122

22-
kbd = Keyboard()
23+
kbd = Keyboard(usb_hid.devices)
2324

2425
# You can adjust this to get the level of sensitivity you want.
2526
cpx.adjust_touch_threshold(100)

CPX_GBoard/universal.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
# from digitalio import DigitalInOut, Direction, Pull
2121
# import board
2222

23-
# Uncomment the next 2 lines if you want to use HID output
23+
# Uncomment the next 3 lines if you want to use HID output
2424
# from adafruit_hid.keyboard import Keyboard
2525
# from adafruit_hid.keycode import Keycode
26+
# import usb_hid
2627

2728
DOT_DURATION = 0.20
2829
DASH_DURATION = 0.5
@@ -40,7 +41,7 @@
4041
# button_b.pull = Pull.UP
4142

4243
# Uncomment the next line if you want to use HID output
43-
# kbd = Keyboard()
44+
# kbd = Keyboard(usb_hid.devices)
4445

4546

4647

CircuitPython_Essentials/CircuitPython_HID_Keyboard.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import board
66
import digitalio
7+
import usb_hid
78
from adafruit_hid.keyboard import Keyboard
89
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
910
from adafruit_hid.keycode import Keycode
@@ -20,7 +21,7 @@
2021

2122
# The keyboard object!
2223
time.sleep(1) # Sleep for a bit to avoid a race condition on some systems
23-
keyboard = Keyboard()
24+
keyboard = Keyboard(usb_hid.devices)
2425
keyboard_layout = KeyboardLayoutUS(keyboard) # We're in the US :)
2526

2627
# Make all pin objects inputs with pullups

CircuitPython_Essentials/CircuitPython_HID_Mouse.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import analogio
44
import board
55
import digitalio
6+
import usb_hid
67
from adafruit_hid.mouse import Mouse
78

8-
mouse = Mouse()
9+
mouse = Mouse(usb_hid.devices)
910

1011
x_axis = analogio.AnalogIn(board.A0)
1112
y_axis = analogio.AnalogIn(board.A1)

Crank_USB_HID/code.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from adafruit_hid.consumer_control import ConsumerControl
1212
from adafruit_hid.consumer_control_code import ConsumerControlCode
1313
import neopixel
14+
import usb_hid
1415

1516
DOT_COLOR = 0xFF0000 # set to your favorite webhex color
1617
PRESSED_DOT_COLOR = 0x008080 # set to your second-favorite color
@@ -35,7 +36,8 @@
3536
rot_b.pull = Pull.UP
3637

3738
# Used to do HID output, see below
38-
kbd = Keyboard()
39+
kbd = Keyboard(usb_hid.devices)
40+
consumer_control = ConsumerControl(usb_hid.devices)
3941

4042
# time keeper, so we know when to turn off the LED
4143
timestamp = time.monotonic()
@@ -111,12 +113,12 @@
111113

112114
# Check if rotary encoder went up
113115
if encoder_direction == 1:
114-
ConsumerControl().send(ConsumerControlCode.VOLUME_DECREMENT) #Turn Down Volume
116+
consumer_control.send(ConsumerControlCode.VOLUME_DECREMENT) #Turn Down Volume
115117
# kbd.press(Keycode.LEFT_ARROW)
116118
# kbd.release_all()
117119
# Check if rotary encoder went down
118120
if encoder_direction == -1:
119-
ConsumerControl().send(ConsumerControlCode.VOLUME_INCREMENT) #Turn Up Volume
121+
consumer_control.send(ConsumerControlCode.VOLUME_INCREMENT) #Turn Up Volume
120122
# kbd.press(Keycode.RIGHT_ARROW)
121123
# kbd.release_all()
122124
# Button was 'just pressed'

0 commit comments

Comments
 (0)