Skip to content

Commit 387ab8b

Browse files
authored
Merge branch 'master' into swap_hid_api
2 parents bcb98a9 + 8d3236e commit 387ab8b

File tree

6 files changed

+4538
-24
lines changed

6 files changed

+4538
-24
lines changed

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)

Disco_Tie/code.py

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,17 @@
1515
import audiobusio
1616
import board
1717
import neopixel
18-
from adafruit_ble.uart_server import UARTServer
18+
19+
from adafruit_ble import BLERadio
20+
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
21+
from adafruit_ble.services.nordic import UARTService
1922
from adafruit_bluefruit_connect.packet import Packet
2023
from adafruit_bluefruit_connect.color_packet import ColorPacket
2124
from adafruit_bluefruit_connect.button_packet import ButtonPacket
2225

23-
uart_server = UARTServer()
26+
ble = BLERadio()
27+
uart_service = UARTService()
28+
advertisement = ProvideServicesAdvertisement(uart_service)
2429

2530
# User input vars
2631
mode = 0 # 0=audio, 1=rainbow, 2=larsen_scanner, 3=solid
@@ -29,6 +34,9 @@
2934
# Audio meter vars
3035
PEAK_COLOR = (100, 0, 255)
3136
NUM_PIXELS = 10
37+
NEOPIXEL_PIN = board.A1
38+
# Use this instead if you want to use the NeoPixels on the Circuit Playground Bluefruit.
39+
# NEOPIXEL_PIN = board.NEOPIXEL
3240
CURVE = 2
3341
SCALE_EXPONENT = math.pow(10, CURVE * -0.1)
3442
NUM_SAMPLES = 160
@@ -62,7 +70,7 @@ def volume_color(volume):
6270
return 200, volume * (255 // NUM_PIXELS), 0
6371

6472
# Set up NeoPixels and turn them all off.
65-
pixels = neopixel.NeoPixel(board.A1, NUM_PIXELS, brightness=0.1, auto_write=False)
73+
pixels = neopixel.NeoPixel(NEOPIXEL_PIN, NUM_PIXELS, brightness=0.1, auto_write=False)
6674
pixels.fill(0)
6775
pixels.show()
6876

@@ -191,15 +199,18 @@ def change_speed(mod, old_speed):
191199
return(new_speed, map_value(new_speed, 10.0, 0.0, 0.01, 0.3))
192200

193201
while True:
194-
# While BLE is *not* connected
195-
if not uart_server.connected:
196-
# OK to call again even if already advertising
197-
uart_server.start_advertising()
202+
ble.start_advertising(advertisement)
203+
while not ble.connected:
204+
pass
198205

199206
# While BLE is connected
200-
else:
201-
if uart_server.in_waiting:
202-
packet = Packet.from_stream(uart_server)
207+
while ble.connected:
208+
if uart_service.in_waiting:
209+
try:
210+
packet = Packet.from_stream(uart_service)
211+
# Ignore malformed packets.
212+
except ValueError:
213+
continue
203214

204215
# Received ColorPacket
205216
if isinstance(packet, ColorPacket):
@@ -221,12 +232,12 @@ def change_speed(mod, old_speed):
221232
elif packet.button == ButtonPacket.BUTTON_4:
222233
mode = 3
223234

224-
# Determine animation based on mode
225-
if mode == 0:
226-
peak = audio_meter(peak)
227-
elif mode == 1:
228-
rainbow_cycle(0.001)
229-
elif mode == 2:
230-
larsen(wait)
231-
elif mode == 3:
232-
solid(user_color)
235+
# Determine animation based on mode
236+
if mode == 0:
237+
peak = audio_meter(peak)
238+
elif mode == 1:
239+
rainbow_cycle(0.001)
240+
elif mode == 2:
241+
larsen(wait)
242+
elif mode == 3:
243+
solid(user_color)

PyPortal_MQTT_Control/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## The PyPortal MQTT Sensor Node/Control Pad tutorial on the Adafruit Learning System
2+
3+
The code in this repo accompanies the Adafruit tutorial
4+
PyPortal MQTT Sensor Node/Control Pad
5+
https://learn.adafruit.com/pyportal-mqtt-sensor-node-control-pad
6+
7+
The *appropriate code file file should be copied onto the **CIRCUITPY** flash drive as **code.py** that appears
8+
when you plug the CircuitPlayground Express into your computer via a known good USB cable.
9+
10+
If the only drive name you get is named **CPLAYBOOT**, CircuitPython may not be loaded
11+
on the board. You can load CircuitPython [per this guide](https://learn.adafruit.com/adafruit-circuit-playground-express/circuitpython-quickstart). Then you should be able to see the **CIRCUITPY** drive when connected via USB.
12+
13+
CircuitPython resources may be found at https://CircuitPython.Org/
14+
15+
Learning Guide by Richard Albritton for Adafruit Industries, January, 2020
16+
17+
MIT License, include all this text in any redistribution
18+
19+
Support Open Source development by buying your materials at [Adafruit.com](https://www.adafruit.com/).

0 commit comments

Comments
 (0)