Skip to content

Commit a842642

Browse files
authored
Merge branch 'master' into fix-pyportal-mqtt-sensor-node
2 parents 1a37e67 + e2afae0 commit a842642

File tree

8 files changed

+318
-6
lines changed

8 files changed

+318
-6
lines changed

BLE_MIDI_Robot_Xylophone/code.py

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import time
2+
import board
3+
import busio
4+
from adafruit_mcp230xx.mcp23017 import MCP23017
5+
from digitalio import Direction
6+
import adafruit_ble
7+
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
8+
import adafruit_ble_midi
9+
10+
# These import auto-register the message type with the MIDI machinery.
11+
# pylint: disable=unused-import
12+
import adafruit_midi
13+
from adafruit_midi.control_change import ControlChange
14+
from adafruit_midi.midi_message import MIDIUnknownEvent
15+
from adafruit_midi.note_off import NoteOff
16+
from adafruit_midi.note_on import NoteOn
17+
from adafruit_midi.pitch_bend import PitchBend
18+
19+
# i2c setup
20+
i2c = busio.I2C(board.SCL, board.SDA)
21+
22+
# i2c addresses for muxes
23+
mcp1 = MCP23017(i2c, address=0x20)
24+
mcp2 = MCP23017(i2c, address=0x21)
25+
26+
# 1st solenoid array, corresponds with 1st mux
27+
noids0 = []
28+
29+
for pin in range(16):
30+
noids0.append(mcp1.get_pin(pin))
31+
for n in noids0:
32+
n.direction = Direction.OUTPUT
33+
34+
# 2nd solenoid array, corresponds with 2nd mux
35+
noids1 = []
36+
37+
for pin in range(16):
38+
noids1.append(mcp2.get_pin(pin))
39+
for n in noids1:
40+
n.direction = Direction.OUTPUT
41+
42+
# MIDI note arrays. notes0 = noids0; notes1 = noids1
43+
notes0 = [55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70]
44+
notes1 = [71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86]
45+
46+
# setup MIDI BLE service
47+
midi_service = adafruit_ble_midi.MIDIService()
48+
advertisement = ProvideServicesAdvertisement(midi_service)
49+
50+
# BLE connection setup
51+
ble = adafruit_ble.BLERadio()
52+
if ble.connected:
53+
for c in ble.connections:
54+
c.disconnect()
55+
56+
# MIDI in setup
57+
midi = adafruit_midi.MIDI(midi_in=midi_service, in_channel=0)
58+
59+
# start BLE advertising
60+
print("advertising")
61+
ble.start_advertising(advertisement)
62+
63+
# delay for solenoids
64+
speed = 0.01
65+
66+
while True:
67+
68+
# waiting for BLE connection
69+
print("Waiting for connection")
70+
while not ble.connected:
71+
pass
72+
print("Connected")
73+
# delay after connection established
74+
time.sleep(1.0)
75+
76+
while ble.connected:
77+
78+
# msg holds MIDI messages
79+
msg = midi.receive()
80+
81+
for i in range(16):
82+
# states for solenoid on/off
83+
# noid0 = mux1
84+
# noid1 = mux2
85+
noid0_output = noids0[i]
86+
noid1_output = noids1[i]
87+
88+
# states for MIDI note recieved
89+
# notes0 = mux1
90+
# notes1 = mux2
91+
notes0_played = notes0[i]
92+
notes1_played = notes1[i]
93+
94+
# if NoteOn msg comes in and the MIDI note # matches with predefined notes:
95+
if isinstance(msg, NoteOn) and msg.note is notes0_played:
96+
print(time.monotonic(), msg.note)
97+
98+
# solenoid is triggered
99+
noid0_output.value = True
100+
# quick delay
101+
time.sleep(speed)
102+
# solenoid retracts
103+
noid0_output.value = False
104+
105+
# identical to above if statement but for mux2
106+
if isinstance(msg, NoteOn) and msg.note is notes1_played:
107+
print(time.monotonic(), msg.note)
108+
109+
noid1_output.value = True
110+
111+
time.sleep(speed)
112+
113+
noid1_output.value = False
114+
115+
# if BLE disconnects try reconnecting
116+
print("Disconnected")
117+
print()
118+
ble.start_advertising(advertisement)

CircuitPython_JEplayer_mp3/code.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ def __init__(self):
7272
self.group = displayio.Group(max_size=4)
7373
self.glyph_width, self.glyph_height = font.get_bounding_box()[:2]
7474
self.pbar = ProgressBar(0, 0, board.DISPLAY.width,
75-
self.glyph_height, bar_color=0x0000ff,
75+
self.glyph_height*2, bar_color=0x0000ff,
7676
outline_color=0x333333, stroke=1)
7777
self.iconbar = icons.IconBar()
78-
self.iconbar.group.y = 112
78+
self.iconbar.group.y = 1000
7979
for i in range(5, 8):
8080
self.iconbar.icons[i].x += 32
8181
self.label = adafruit_display_text.label.Label(font, line_spacing=1.0,
@@ -471,6 +471,7 @@ def play_all(playlist, *, folder='', trim=0, location='/sd'):
471471
'folder' is a display name for the user."""
472472
i = 0
473473
board.DISPLAY.show(playback_display.group)
474+
playback_display.iconbar.group.y = 112
474475
while 0 <= i < len(playlist):
475476
filename = playlist[i]
476477
i = play_one_file(i, join(location, filename), folder, filename[trim:-4], len(playlist))
-9.07 KB
Binary file not shown.

CircuitPython_RGBMatrix/fruit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Wheel(displayio.TileGrid):
3636
def __init__(self):
3737
# Portions of up to 3 tiles are visible.
3838
super().__init__(bitmap=bitmap, pixel_shader=displayio.ColorConverter(),
39-
width=1, height=3, tile_width=20)
39+
width=1, height=3, tile_width=20, tile_height=24)
4040
self.order = shuffled(range(20))
4141
self.state = STOPPED
4242
self.pos = 0

ItsyBitsy_Infinity_Cube/code.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
import board
66
import neopixel
7-
from adafruit_led_animation.animation import Comet, Sparkle, AnimationGroup,\
8-
AnimationSequence
7+
from adafruit_led_animation.animation.comet import Comet
8+
from adafruit_led_animation.animation.sparkle import Sparkle
9+
from adafruit_led_animation.group import AnimationGroup
10+
from adafruit_led_animation.sequence import AnimationSequence
911
import adafruit_led_animation.color as color
1012

1113
from adafruit_ble import BLERadio

ItsyBitsy_Keybow/itsybitsy_keybow.py

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# ItsyBitsy Keypad
2+
# Uses ItsyBitsy M4/M0 plus Pimoroni Keybow
3+
# To build a customizable USB keypad
4+
5+
import time
6+
import board
7+
from digitalio import DigitalInOut, Direction, Pull
8+
import usb_hid
9+
from adafruit_hid.keyboard import Keyboard
10+
from adafruit_hid.keycode import Keycode
11+
from adafruit_hid.consumer_control import ConsumerControl
12+
from adafruit_hid.consumer_control_code import ConsumerControlCode
13+
import adafruit_dotstar as dotstar
14+
15+
dots = dotstar.DotStar(board.SCK, board.MOSI, 12, brightness=0.4)
16+
17+
RED = 0xFF0000
18+
AMBER = 0xAA9900
19+
BLUE = 0x0066FF
20+
MAGENTA = 0xFF00FF
21+
PURPLE = 0x3B0F85
22+
BLACK = 0x000000
23+
24+
kbd = Keyboard(usb_hid.devices)
25+
cc = ConsumerControl(usb_hid.devices)
26+
27+
orientation = 1 # 0 = portrait/vertical, 1 = landscape/horizontal
28+
if orientation == 0:
29+
key_dots = [0, 4, 8, 1, 5, 9, 2, 6, 10, 3, 7, 11]
30+
# 0 #4 #8
31+
# 1 #5 #9
32+
# 2 #6 #10
33+
# 3 #7 #11
34+
if orientation == 1:
35+
key_dots = [3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8]
36+
# 3 #2 #1 #0
37+
# 7 #6 #5 #4
38+
# 11 #10 #9 #8
39+
40+
41+
def dot_on(dot, color):
42+
dots[dot] = color
43+
44+
45+
def dot_off(dot):
46+
dots[dot] = BLACK
47+
48+
49+
# Pin definitions
50+
if orientation == 0: # 0 = portrait/vertical
51+
pins = [
52+
board.D11,
53+
board.D12,
54+
board.D2,
55+
board.D10,
56+
board.D9,
57+
board.D7,
58+
board.A5,
59+
board.A4,
60+
board.A3,
61+
board.A2,
62+
board.A1,
63+
board.A0,
64+
]
65+
if orientation == 1: # 1 = landscape/horizontal
66+
pins = [
67+
board.A2,
68+
board.A5,
69+
board.D10,
70+
board.D11,
71+
board.A1,
72+
board.A4,
73+
board.D9,
74+
board.D12,
75+
board.A0,
76+
board.A3,
77+
board.D7,
78+
board.D2,
79+
]
80+
# the two command types -- MEDIA for ConsumerControlCodes, KEY for Keycodes
81+
# this allows button press to send the correct HID command for the type specified
82+
MEDIA = 1
83+
KEY = 2
84+
keymap = {
85+
(0): (AMBER, MEDIA, ConsumerControlCode.PLAY_PAUSE),
86+
(1): (AMBER, MEDIA, ConsumerControlCode.MUTE),
87+
(2): (AMBER, MEDIA, ConsumerControlCode.VOLUME_DECREMENT),
88+
(3): (AMBER, MEDIA, ConsumerControlCode.VOLUME_INCREMENT),
89+
(4): (BLUE, KEY, (Keycode.GUI, Keycode.C)),
90+
(5): (BLUE, KEY, (Keycode.GUI, Keycode.V)),
91+
(6): (MAGENTA, KEY, [Keycode.UP_ARROW]),
92+
(7): (PURPLE, KEY, [Keycode.BACKSPACE]),
93+
(8): (BLUE, KEY, [Keycode.SPACE]),
94+
(9): (MAGENTA, KEY, [Keycode.LEFT_ARROW]),
95+
(10): (MAGENTA, KEY, [Keycode.DOWN_ARROW]),
96+
(11): (MAGENTA, KEY, [Keycode.RIGHT_ARROW]),
97+
}
98+
99+
switches = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
100+
for i in range(12):
101+
switches[i] = DigitalInOut(pins[i])
102+
switches[i].direction = Direction.INPUT
103+
switches[i].pull = Pull.UP
104+
105+
switch_state = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
106+
107+
print("ItsyBitsy Keybow")
108+
109+
# Starup lights
110+
for k in range(12):
111+
dot_on(key_dots[k], RED)
112+
time.sleep(0.05)
113+
dot_on(key_dots[k], keymap[k][0]) # use individual key colors from set
114+
time.sleep(0.05)
115+
116+
while True:
117+
for button in range(12):
118+
if switch_state[button] == 0:
119+
if not switches[button].value:
120+
try:
121+
if keymap[button][1] == KEY:
122+
kbd.press(*keymap[button][2])
123+
else:
124+
cc.send(keymap[button][2])
125+
dot_on(key_dots[button], RED)
126+
except ValueError: # deals w six key limit
127+
pass
128+
print("pressed key{}".format(button))
129+
switch_state[button] = 1
130+
131+
if switch_state[button] == 1:
132+
if switches[button].value:
133+
try:
134+
if keymap[button][1] == KEY:
135+
kbd.release(*keymap[button][2])
136+
dot_on(key_dots[button], keymap[button][0])
137+
except ValueError:
138+
pass
139+
print("released key{}".format(button))
140+
switch_state[button] = 0
141+
142+
time.sleep(0.01) # debounce

MP3_Tap_Player/mp3_tap_player.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# MP3 playback with tap trigger
2+
# Works on M4 and nRF52840 based boards with accelerometer or Propmaker
3+
import time
4+
import board
5+
import busio
6+
import digitalio
7+
import audioio
8+
import audiomp3
9+
import adafruit_lis3dh
10+
11+
startup_play = False # set to True to play all samples once on startup
12+
13+
# Set up accelerometer on I2C bus
14+
i2c = busio.I2C(board.SCL, board.SDA)
15+
int1 = digitalio.DigitalInOut(board.D6)
16+
accel = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)
17+
accel.set_tap(1, 100) # single or double-tap, threshold
18+
19+
# Set up speaker enable pin
20+
enable = digitalio.DigitalInOut(board.D10)
21+
enable.direction = digitalio.Direction.OUTPUT
22+
enable.value = True
23+
24+
speaker = audioio.AudioOut(board.A0)
25+
26+
sample_number = 0
27+
28+
print("Lars says, 'Hello, CVT Joseph. Tap to play.'")
29+
30+
if startup_play: # Play all on startup
31+
for i in range(10):
32+
sample = "/lars/lars_0{}.mp3".format(i)
33+
print("Now playing: '{}'".format(sample))
34+
mp3stream = audiomp3.MP3Decoder(open(sample, "rb"))
35+
speaker.play(mp3stream)
36+
37+
while speaker.playing:
38+
time.sleep(0.1)
39+
enable.value = speaker.playing
40+
41+
42+
while True:
43+
if accel.tapped and speaker.playing is False:
44+
sample = "/lars/lars_0{}.mp3".format(sample_number)
45+
print("Now playing: '{}'".format(sample))
46+
mp3stream = audiomp3.MP3Decoder(open(sample, "rb"))
47+
speaker.play(mp3stream)
48+
sample_number = (sample_number + 1) % 10
49+
enable.value = speaker.playing

library.deps

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
depends=Adafruit ILI9341, Adafruit BusIO, SD, Adafruit NeoPixel, Adafruit VS1053 Library, Adafruit BluefruitLE nRF51, Adafruit seesaw Library, Ethernet, Adafruit IO Arduino, Adafruit LSM303, FastLED, Adafruit LiquidCrystal, Adafruit SoftServo, TinyWireM, Adafruit AM radio library, WaveHC, Adafruit LED Backpack Library, MAX31850 OneWire, Adafruit VC0706 Serial Camera Library, RTClib, Adafruit SleepyDog Library, Adafruit Thermal Printer Library, Adafruit Zero I2S Library, Adafruit EPD, Adafruit SSD1351 library, Adafruit FONA Library, Adafruit Motor Shield V2 Library, Adafruit NeoMatrix, Adafruit Soundboard library, Adafruit Circuit Playground, MIDI, ArduinoJson, Adafruit TCS34725, Adafruit Pixie, Adafruit GPS Library, TinyGPS, WiFi101, Adafruit DotStar, Adafruit Si7021 Library, Adafruit WS2801 Library, Mouse, Keyboard, Time, IRremote, Adafruit LSM9DS0 Library, Adafruit Arcada Library, MIDIUSB, PubSubClient, Adafruit LIS2MDL, Adafruit NeoPXL8, Adafruit MCP23017 Arduino Library, Adafruit MLX90640, LiquidCrystal, Adafruit NeoTrellis M4 Library, RGB matrix Panel, Adafruit MLX90614 Library, Adafruit RGB LCD Shield Library, MAX6675 library, Adafruit_mp3, Adafruit Keypad, Adafruit Arcada GifDecoder, Keypad, Neosegment, Encoder, Adafruit TiCoServo, Adafruit Trellis Library, FauxmoESP, Adafruit LSM303 Accel, Adafruit LSM303DLH Mag, CapacitiveSensor, Adafruit Zero PDM Library, Adafruit DMA neopixel library, elapsedMillis, DST RTC
1+
depends=Adafruit ILI9341, Adafruit BusIO, SD, Adafruit NeoPixel, Adafruit VS1053 Library, Adafruit BluefruitLE nRF51, Adafruit seesaw Library, Ethernet, Adafruit IO Arduino, Adafruit LSM303, FastLED, Adafruit LiquidCrystal, Adafruit SoftServo, TinyWireM, Adafruit AM radio library, WaveHC, Adafruit LED Backpack Library, MAX31850 OneWire, Adafruit VC0706 Serial Camera Library, RTClib, Adafruit SleepyDog Library, Adafruit Thermal Printer Library, Adafruit Zero I2S Library, Adafruit EPD, Adafruit SSD1351 library, Adafruit FONA Library, Adafruit Motor Shield V2 Library, Adafruit NeoMatrix, Adafruit Soundboard library, Adafruit Circuit Playground, MIDI, ArduinoJson, Adafruit TCS34725, Adafruit Pixie, Adafruit GPS Library, TinyGPS, WiFi101, Adafruit DotStar, Adafruit Si7021 Library, Adafruit WS2801 Library, Mouse, Keyboard, Time, IRremote, Adafruit LSM9DS0 Library, Adafruit Arcada Library, MIDIUSB, PubSubClient, Adafruit LIS2MDL, Adafruit NeoPXL8, Adafruit MCP23017 Arduino Library, Adafruit MLX90640, LiquidCrystal, Adafruit NeoTrellis M4 Library, RGB matrix Panel, Adafruit MLX90614 Library, Adafruit RGB LCD Shield Library, MAX6675 library, Adafruit MP3, Adafruit Keypad, Adafruit Arcada GifDecoder, Keypad, Neosegment, Encoder, Adafruit TiCoServo, Adafruit Trellis Library, FauxmoESP, Adafruit LSM303 Accel, Adafruit LSM303DLH Mag, CapacitiveSensor, Adafruit Zero PDM Library, Adafruit DMA neopixel library, elapsedMillis, DST RTC

0 commit comments

Comments
 (0)