Skip to content

Commit beef3e0

Browse files
committed
Merge branch 'main' of github.com:adafruit/Adafruit_Learning_System_Guides
2 parents 0c3a01a + 52cee1e commit beef3e0

File tree

95 files changed

+4906
-86
lines changed

Some content is hidden

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

95 files changed

+4906
-86
lines changed

BLE_Client_Server/server/code.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
# SPDX-License-Identifier: MIT
44

55
from time import sleep
6-
from adafruit_ble.uart_server import UARTServer
6+
from adafruit_ble import BLERadio
7+
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
8+
from adafruit_ble.services.nordic import UARTService
79
from adafruit_bluefruit_connect.packet import Packet
810
from adafruit_bluefruit_connect.button_packet import ButtonPacket
911
from adafruit_bluefruit_connect.color_packet import ColorPacket
@@ -17,15 +19,16 @@
1719
solenoid.direction = Direction.OUTPUT
1820
solenoid.value = False
1921

20-
uart_server = UARTServer()
22+
ble = BLERadio()
23+
uart_server = UARTService()
24+
advertisement = ProvideServicesAdvertisement(uart_server)
2125

2226
while True:
23-
uart_server.start_advertising() # Advertise when not connected.
24-
25-
while not uart_server.connected: # Wait for connection
27+
ble.start_advertising(advertisement) # Advertise when not connected.
28+
while not ble.connected:
2629
pass
2730

28-
while uart_server.connected: # Connected
31+
while ble.connected: # Connected
2932
if uart_server.in_waiting: # Check BLE commands
3033
packet = Packet.from_stream(uart_server)
3134
if isinstance(packet, ButtonPacket):

Bubble_Table_IR_Control/code.py

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
# SPDX-FileCopyrightText: 2017 John Park for Adafruit Industries
2+
# Modified 2023 by Erin St Blaine
3+
#
4+
# SPDX-License-Identifier: MIT
5+
6+
7+
import board
8+
import pulseio
9+
import neopixel
10+
import adafruit_irremote
11+
from rainbowio import colorwheel
12+
from adafruit_led_animation.sequence import AnimationSequence
13+
from adafruit_led_animation.animation.solid import Solid
14+
from adafruit_led_animation.animation.rainbow import Rainbow
15+
from adafruit_led_animation.animation.sparkle import Sparkle
16+
from adafruit_led_animation.animation.rainbowchase import RainbowChase
17+
from adafruit_led_animation.animation.rainbowcomet import RainbowComet
18+
from adafruit_led_animation.animation.chase import Chase
19+
from adafruit_led_animation.animation.comet import Comet
20+
from adafruit_led_animation.animation.pulse import Pulse
21+
from adafruit_led_animation.animation.SparklePulse import SparklePulse
22+
import adafruit_led_animation.color as color
23+
24+
NUMBER_OF_PIXELS = 85
25+
pixels = neopixel.NeoPixel(board.D13, NUMBER_OF_PIXELS)
26+
27+
# Define the brightness levels and their corresponding values
28+
# Start at a non-blinding brightness.
29+
BRIGHTNESS_LEVELS = (0.025, 0.05, 0.1, 0.2, 0.4, 0.6, 0.7, 0.8, 1.0)
30+
brightness_index = 2
31+
pixels.brightness = BRIGHTNESS_LEVELS[brightness_index]
32+
33+
pulsein = pulseio.PulseIn(board.A0, maxlen=120, idle_state=True)
34+
decoder = adafruit_irremote.GenericDecode()
35+
36+
SPEEDS = (0.25, 0.125, 0.1, 0.08, 0.05, 0.02, 0.01) # Customize speed levels here
37+
speed_index = 4
38+
39+
def setup_animations():
40+
"""Set up all the available animations."""
41+
# Animation Setup
42+
rainbow = Rainbow(pixels, speed=SPEEDS[speed_index], period=2, name="rainbow", step=3)
43+
sparkle = Sparkle(pixels, speed=SPEEDS[speed_index], color=color.WHITE, name="sparkle")
44+
solid = Solid(pixels, color=colorwheel(0), name="solid")
45+
# Make the Solid animation changeable quickly.
46+
solid.speed = 0.01
47+
off = Solid(pixels, color=color.BLACK, name="off")
48+
rainbow = Rainbow(pixels, speed=SPEEDS[speed_index], period=6, name="rainbow", step=2.4)
49+
rainbow_carousel = RainbowChase(pixels, speed=SPEEDS[speed_index], size=4, spacing=1, step=20)
50+
party_chase = RainbowChase(pixels, speed=SPEEDS[speed_index], size=1, spacing=5, step=6)
51+
rainbow_chase2 = RainbowChase(pixels, speed=SPEEDS[speed_index], size=10, spacing=1, step=18)
52+
chase = Chase(pixels, speed=SPEEDS[speed_index], color=color.RED, size=1, spacing=6)
53+
rainbow_comet2 = RainbowComet(
54+
pixels, speed=0.02, tail_length=104, colorwheel_offset=80, bounce=False)
55+
rainbow_comet3 = RainbowComet(
56+
pixels, speed=SPEEDS[speed_index], tail_length=25,
57+
colorwheel_offset=128, step=4, bounce=False)
58+
lava = Comet(pixels, speed=SPEEDS[speed_index],
59+
color=color.ORANGE, tail_length=40, bounce=False)
60+
sparkle1 = Sparkle(pixels, speed=SPEEDS[speed_index], color=color.BLUE, num_sparkles=10)
61+
pulse = Pulse(pixels, speed=0.1, color=color.AMBER, period=3)
62+
sparkle_pulse = SparklePulse(pixels, speed=0.05, period=2, color=color.JADE, max_intensity=3)
63+
64+
# Animation Sequence Playlist -- rearrange to change the order of animations
65+
# advance_interval is None, so the animations change only under user control.
66+
all_animations = AnimationSequence(
67+
rainbow,
68+
rainbow_chase2,
69+
rainbow_carousel,
70+
party_chase,
71+
rainbow_comet2,
72+
rainbow_comet3,
73+
sparkle_pulse,
74+
pulse,
75+
chase,
76+
rainbow,
77+
solid,
78+
sparkle,
79+
lava,
80+
sparkle1,
81+
off,
82+
auto_clear=True,
83+
auto_reset=True,
84+
advance_interval=None,
85+
)
86+
return all_animations
87+
88+
# IR Remote Mapping for the Adafruit mini IR remote
89+
# https://www.adafruit.com/product/389
90+
91+
CMD_1 = 247 # 1: [255, 2, 247, 8]
92+
CMD_2 = 119 # 2: [255, 2, 119, 136]
93+
CMD_3 = 183 # 3: [255, 2, 183, 72]
94+
CMD_4 = 215 # 4: [255, 2, 215, 40]
95+
CMD_5 = 87 # 5: [255, 2, 87, 168]
96+
CMD_6 = 151 # 6: [255, 2, 151, 104]
97+
CMD_7 = 231 # 7: [255, 2, 231, 24]
98+
CMD_8 = 103 # 8: [255, 2, 103, 152]
99+
CMD_9 = 167 # 9: [255, 2, 167, 88]
100+
CMD_0 = 207 # 0: [255, 2, 207, 48]
101+
102+
CMD_UP = 95 # ^ : [255, 2, 95, 160]
103+
CMD_DOWN = 79 # v : [255, 2, 79, 176]
104+
CMD_RIGHT = 175 # > : [255, 2, 175, 80]
105+
CMD_LEFT = 239 # < : [255, 2, 239, 16]
106+
107+
CMD_ENTER_SAVE = 111 # Enter/Save: [255, 2, 111, 144]
108+
CMD_SETUP = 223 # Setup: [255, 2, 223, 32]
109+
CMD_STOP_MODE = 159 # Stop/Mode: [255, 2, 159, 96]
110+
CMD_BACK = 143 # Back: [255, 2, 143, 112]
111+
112+
CMD_VOL_DOWN = 255 # Vol - : [255, 2, 255, 0]
113+
CMD_VOL_UP = 191 # Vol + : [255, 2, 191, 64]
114+
CMD_PLAY_PAUSE = 127 # Play/Pause: [255, 2, 127, 128]
115+
CMD_REPEAT = True # short code: repeat of previous command
116+
117+
118+
def read_command():
119+
"""Try to read an IR command. If none seen or if error, return None."""
120+
try:
121+
pulses = decoder.read_pulses(pulsein, blocking=False)
122+
if pulses:
123+
code = decoder.decode_bits(pulses)
124+
if len(code) > 3:
125+
print("Decoded:", code)
126+
return code[2]
127+
# if code is less than or equal to 3 characters long or no pulses received
128+
return None
129+
except adafruit_irremote.IRNECRepeatException: # unusual short code!
130+
print("NEC repeat!")
131+
return CMD_REPEAT
132+
except adafruit_irremote.IRDecodeException as e: # failed to decode
133+
print("Failed to decode:", e)
134+
return None
135+
except MemoryError as e:
136+
print("Memory error: ", e)
137+
return None
138+
139+
SOLID_COLORS = {
140+
CMD_0 : color.BLACK,
141+
CMD_1 : color.RED,
142+
CMD_2 : color.GREEN,
143+
CMD_3 : color.WHITE,
144+
CMD_4 : color.BLUE,
145+
CMD_5 : color.PINK,
146+
CMD_6 : color.YELLOW,
147+
CMD_7 : color.PURPLE,
148+
CMD_8 : color.TEAL,
149+
CMD_9 : color.ORANGE,
150+
}
151+
152+
# main program
153+
154+
animations = setup_animations()
155+
last_command = None
156+
157+
while True:
158+
command = read_command()
159+
if command is None:
160+
# Nothing read, just keep animating.
161+
animations.animate() # Run one animation cycle.
162+
continue
163+
164+
if command == CMD_REPEAT:
165+
command = last_command
166+
167+
last_command = command
168+
print("Command", command)
169+
170+
171+
# See if the command was a number button. Fetch the animation color if it is.
172+
solid_color = SOLID_COLORS.get(command, None)
173+
if solid_color:
174+
# Jump to the "solid" animation. Set its color to
175+
# the chosen color.
176+
animations.activate("solid")
177+
animations.current_animation.color = solid_color
178+
elif command == CMD_LEFT:
179+
animations.previous()
180+
elif command == CMD_RIGHT:
181+
animations.next()
182+
elif command == CMD_DOWN:
183+
# Slow down current animation
184+
if speed_index > 0:
185+
speed_index -= 1
186+
animations.current_animation.speed = SPEEDS[speed_index]
187+
print("speed of current animation is now:", animations.current_animation.speed)
188+
elif command == CMD_UP:
189+
if speed_index < len(SPEEDS) - 1:
190+
speed_index += 1
191+
animations.current_animation.speed = SPEEDS[speed_index]
192+
print("speed of current animation is now:", animations.current_animation.speed)
193+
elif command == CMD_VOL_DOWN:
194+
if brightness_index > 0:
195+
brightness_index -= 1
196+
pixels.brightness = BRIGHTNESS_LEVELS[brightness_index]
197+
print("brightness:", pixels.brightness)
198+
elif command == CMD_VOL_UP:
199+
if brightness_index < len(BRIGHTNESS_LEVELS) - 1:
200+
brightness_index += 1
201+
pixels.brightness = BRIGHTNESS_LEVELS[brightness_index]
202+
print("brightness:", pixels.brightness)

CLUE_Altimeter/code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
# background
4848
bg_bmp, bg_pal = adafruit_imageload.load(
49-
"/network23.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette
49+
"images/network23.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette
5050
)
5151
for i, color in enumerate(bg_pal):
5252
if color == 0xFF0000:
File renamed without changes.

CPBoxing_Glove_Tracker/code.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-FileCopyrightText: 2023 Trevor Beaton for Adafruit Industries
22
#
33
# SPDX-License-Identifier: MIT
4+
import os
45
import time
56
import ssl
67
import math
@@ -13,25 +14,18 @@
1314
from adafruit_adxl34x import ADXL345
1415
from adafruit_lc709203f import LC709203F, PackSize
1516

16-
17-
try:
18-
from secrets import secrets
19-
except ImportError:
20-
print("WiFi and Adafruit IO credentials are kept in secrets.py - please add them there!")
21-
raise
22-
23-
aio_username = secrets["aio_username"]
24-
aio_key = secrets["aio_key"]
17+
aio_username = os.getenv('aio_username')
18+
aio_key = os.getenv('aio_key')
2519

2620
# Wi-Fi
2721
try:
28-
print("Connecting to %s" % secrets["ssid"])
29-
wifi.radio.connect(secrets["ssid"], secrets["password"])
30-
print("Connected to %s!" % secrets["ssid"])
22+
print("Connecting to %s" % os.getenv('CIRCUITPY_WIFI_SSID'))
23+
wifi.radio.connect(os.getenv('CIRCUITPY_WIFI_SSID'), os.getenv('CIRCUITPY_WIFI_PASSWORD'))
24+
print("Connected to %s!" % os.getenv('CIRCUITPY_WIFI_SSID'))
3125
# Wi-Fi connectivity fails with error messages, not specific errors, so this except is broad.
3226
except Exception as e: # pylint: disable=broad-except
33-
print("Failed to connect to WiFi. Error:", e, "\nBoard will hard reset in 5 seconds.")
34-
time.sleep(5)
27+
print("Failed to connect to WiFi. Error:", e, "\nBoard will hard reset in 30 seconds.")
28+
time.sleep(30)
3529
microcontroller.reset()
3630

3731
# Create a socket pool
@@ -40,8 +34,8 @@
4034
# Initialize a new MQTT Client object
4135
mqtt_client = MQTT.MQTT(
4236
broker="io.adafruit.com",
43-
username=secrets["aio_username"],
44-
password=secrets["aio_key"],
37+
username= aio_username,
38+
password= aio_key,
4539
socket_pool=pool,
4640
ssl_context=ssl.create_default_context(),
4741
)
@@ -50,26 +44,27 @@
5044
io = IO_MQTT(mqtt_client)
5145

5246
try:
53-
# If Adafruit IO is not connected...
5447
if not io.is_connected:
5548
# Connect the client to the MQTT broker.
5649
print("Connecting to Adafruit IO...")
5750
io.connect()
5851
print("Connected to Adafruit IO!")
5952
except Exception as e: # pylint: disable=broad-except
6053
print("Failed to get or send data, or connect. Error:", e,
61-
"\nBoard will hard reset in 30 seconds.")
54+
"\nBoard will hard reset in 30 seconds./n")
6255
time.sleep(30)
6356
microcontroller.reset()
6457

65-
threshold = 25 # set threshold value here
58+
threshold = 20 # set threshold value here
6659
time_interval = 0.5 # set the time interval in seconds
6760

6861
# create the I2C bus object
6962
i2c = board.STEMMA_I2C()
63+
7064
# For ADXL345
7165
accelerometer = ADXL345(i2c)
7266

67+
# To monitor the battery
7368
battery_monitor = LC709203F(i2c)
7469
battery_monitor.pack_size = PackSize.MAH400
7570

ChatGPT_Bear/Enclosure/3MF_Files.zip

181 KB
Binary file not shown.

ChatGPT_Bear/Enclosure/CAD_Files.zip

12.4 MB
Binary file not shown.

ChatGPT_Bear/Enclosure/STL_Files.zip

154 KB
Binary file not shown.

0 commit comments

Comments
 (0)