Skip to content

Commit 9cdec01

Browse files
authored
Merge pull request #1 from adafruit/master
updating my local fork
2 parents 44778fe + 152c41f commit 9cdec01

File tree

27 files changed

+1431
-36
lines changed

27 files changed

+1431
-36
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_Essentials/CircuitPython_PWM_Piezo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
while True:
1212
for f in (262, 294, 330, 349, 392, 440, 494, 523):
1313
piezo.frequency = f
14-
piezo.duty_cycle = 65536 // 2 # On 50%
14+
piezo.duty_cycle = 65535 // 2 # On 50%
1515
time.sleep(0.25) # On for 1/4 second
1616
piezo.duty_cycle = 0 # Off
1717
time.sleep(0.05) # Pause between notes

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

FONA_SMS_Sensor/code.py

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
# pylint: disable=unused-import
12
import time
23
import board
34
import busio
45
import digitalio
56
from adafruit_fona.adafruit_fona import FONA
7+
from adafruit_fona.fona_3g import FONA3G
68
import adafruit_bme280
79

810
print("FONA SMS Sensor")
@@ -11,9 +13,12 @@
1113
uart = busio.UART(board.TX, board.RX)
1214
rst = digitalio.DigitalInOut(board.D4)
1315

14-
# Initialize FONA module (this may take a few seconds)
16+
# Use this for FONA800 and FONA808
1517
fona = FONA(uart, rst)
1618

19+
# Use this for FONA3G
20+
# fona = FONA3G(uart, rst)
21+
1722
# Initialize BME280 Sensor
1823
i2c = busio.I2C(board.SCL, board.SDA)
1924
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)
@@ -28,23 +33,11 @@
2833
# Enable FONA SMS notification
2934
fona.enable_sms_notification = True
3035

31-
# store incoming notification info
32-
notification_buf = bytearray(64)
33-
34-
print("FONA Ready!")
36+
print("Listening for messages...")
3537
while True:
36-
if fona.in_waiting: # data is available from FONA
37-
notification_buf = fona.read_line()[1]
38-
# Split out the sms notification slot num.
39-
notification_buf = notification_buf.decode()
40-
if "+CMTI:" not in notification_buf:
41-
continue
42-
sms_slot = notification_buf.split(",")[1]
43-
44-
print("NEW SMS!\n\t Slot: ", sms_slot)
45-
46-
# Get SMS message and address
47-
sender, message = fona.read_sms(sms_slot)
38+
sender, message = fona.receive_sms()
39+
if message:
40+
print("New Message!")
4841
print("FROM: ", sender)
4942
print("MSG: ", message)
5043

@@ -57,16 +50,17 @@
5750
message = message.lower()
5851
message = message.strip()
5952

60-
if message in ['temp', 'temperature', 't']:
53+
if message in ["temp", "temperature", "t"]:
6154
response = "Temperature: %0.1f C" % temp
62-
elif message in ['humid', 'humidity', 'h']:
55+
elif message in ["humid", "humidity", "h"]:
6356
response = "Humidity: %0.1f %%" % humid
64-
elif message in ['pres', 'pressure', 'p']:
57+
elif message in ["pres", "pressure", "p"]:
6558
response = "Pressure: %0.1f hPa" % pres
66-
elif message in ['status', 's']:
67-
response = "Temperature: {0:.2f}C\nHumidity: {1:.1f}% \
68-
Pressure: {2:.1f}hPa".format(temp, humid, pres)
69-
elif message in ['help']:
59+
elif message in ["status", "s"]:
60+
response = "Temperature: {0:.2f}C\nHumidity: {1:.1f}%Pressure: {2:.1f}hPa".format(
61+
temp, humid, pres
62+
)
63+
elif message in ["help"]:
7064
response = "I'm a SMS Sensor - txt me with a command:\
7165
TEMP - Read temperature\
7266
HUMID - Read humidity\
@@ -82,8 +76,3 @@
8276
if not fona.send_sms(int(sender), response):
8377
print("SMS Send Failed")
8478
print("SMS Sent!")
85-
86-
# Delete the original message
87-
if not fona.delete_sms(sms_slot):
88-
print("Could not delete SMS in slot", sms_slot)
89-
print("OK!")

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

0 commit comments

Comments
 (0)