Skip to content

Commit

Permalink
Merge branch 'adafruit:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ladyada authored Dec 4, 2023
2 parents fdaf9f1 + 9de211f commit 5e95fbf
Show file tree
Hide file tree
Showing 779 changed files with 3,636 additions and 465 deletions.
2 changes: 1 addition & 1 deletion 4x4_MIDI_Messenger/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=64)

splash = displayio.Group()
display.show(splash)
display.root_group = splash
font = bitmap_font.load_font('/OCRA_small.pcf')
# main label/MIDI message name text; centered
main_area = label.Label(
Expand Down
2 changes: 1 addition & 1 deletion AHT20_OLED/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

# Make the display context
splash = displayio.Group()
display.show(splash)
display.root_group = splash

text = "hello world"
text_area = label.Label(terminalio.FONT, color=0xFFFF00, x=15, y=0)
Expand Down
2 changes: 1 addition & 1 deletion Adafruit_Feather_TFT_ESP32-S2/TFT_GitHub_Stars/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
text_area.x = 135
text_area.y = 90
group.append(text_area)
display.show(group)
display.root_group = group

# Connect to WiFi
print("Connecting to %s"%secrets["ssid"])
Expand Down
2 changes: 1 addition & 1 deletion Adafruit_Feather_TFT_ESP32-S2/TFT_Hello_World/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
text_area = bitmap_label.Label(terminalio.FONT, text=text, scale=scale)
text_area.x = 10
text_area.y = 10
board.DISPLAY.show(text_area)
board.DISPLAY.root_group = text_area

while True:
pass
2 changes: 1 addition & 1 deletion Adafruit_Feather_TFT_ESP32-S2/TFT_bitmap_display/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
tile_grid = TileGrid(bitmap=blinka_img, pixel_shader=blinka_img.pixel_shader)
main_group.append(tile_grid)

board.DISPLAY.show(main_group)
board.DISPLAY.root_group = main_group

tile_grid.x = board.DISPLAY.width // 2 - blinka_img.width // 2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

print("IC version:", hex(sensor.ic_version))

board.DISPLAY.show(main_group)
board.DISPLAY.root_group = main_group

while True:
text_area.text = "Battery:\n{:.1f} Volts \n{}%".format(sensor.cell_voltage, sensor.cell_percent)
Expand Down
2 changes: 1 addition & 1 deletion Baudot_TTY/baudot_tty_GUI/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
dot = Circle(220, 60, 8, outline=VFD_GREEN, fill=VFD_BG)
screen.append(dot)

clue.display.show(screen)
clue.display.root_group = screen

# constants for sine wave generation
SIN_LENGTH = 100 # more is less choppy
Expand Down
142 changes: 142 additions & 0 deletions Bricktunes_LEGO_Color_Synth/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# SPDX-FileCopyrightText: 2023 John Park for Adafruit
# SPDX-License-Identifier: MIT

# Bricktunes LEGO Color Synth
# Feather RP2040 Prop-Maker + AS7341 Color Sensor
# Color comparison code and chime library by CGrover

import time
import math
import board
import digitalio
import audiobusio
from adafruit_as7341 import AS7341, Gain
import audiomixer
from cedargrove_chime import Chime, Voice, Material, Striker

DEBUG = False # Useful for tuning reference color values by printing them
TOLERANCE = 800 # The color matching tolerance index (0 to 8 * max_sensor_count)

sensor = AS7341(board.STEMMA_I2C())
sensor.astep = 128 # (999) The integration time step size in 2.78 microsecond increments
sensor.atime = 50 # The integration time step count.
sensor.gain = Gain.GAIN_256X
sensor.led_current = 4 # increments in units of 4
sensor.led = True
max_sensor_count = (sensor.astep + 1) * (sensor.atime + 1)

# ===================================================
# color lists as 8-channel tuples (channels[0:8])
brick_full_spectrum_values = [
(94, 1310, 1736, 1075, 592, 437, 497, 383), # Blue
(148, 324, 838, 2577, 2363, 1259, 929, 819), # Bright Green
(381, 576, 850, 1619, 3688, 5532, 6291, 4250), # Bright Lt Orange
(404, 2300, 2928, 2385, 2679, 3804, 5576, 4284), # Bright Pink
(545, 1276, 1513, 1178, 2291, 6579, 6579, 6486), # Coral
(136, 1055, 1223, 745, 748, 768, 1205, 1100), # Dark Purple
(85, 731, 1375, 1604, 1019, 557, 533, 370), # Dark Turquoise
(451, 2758, 3786, 2880, 3007, 3064, 4539, 3656), # Lavender
(214, 300, 771, 1811, 3245, 2897, 2051, 1392), # Lime
(188, 341, 435, 507, 625, 1703, 4361, 3692), # Red
(182, 870, 1455, 1799, 2149, 1879, 1702, 1273), # Sand Green
(461, 497, 878, 2412, 4699, 5935, 6579, 4677) # Yellow
]

brick_color_names = [
"Blue",
"Bright Green",
"Bright Light Orange",
"Bright Pink",
"Coral",
"Dark Purple",
"Dark Turquoise",
"Lavender",
"Lime",
"Red",
"Sand Green",
"Yellow"
]

brick_states = [False] * (len(brick_color_names))
gap_state = False

# ===================================================
# audio setup
power = digitalio.DigitalInOut(board.EXTERNAL_POWER)
power.switch_to_output(value=True)
audio_output = audiobusio.I2SOut(board.I2S_BIT_CLOCK, board.I2S_WORD_SELECT, board.I2S_DATA)

mixer = audiomixer.Mixer(sample_rate=11020, buffer_size=4096, voice_count=1, channel_count=1)
audio_output.play(mixer)
mixer.voice[0].level = 0.50 # adjust this for overall volume

brickscale = [
"C5", "D5", "E5", "F5", "G5", "A5", "B5",
"C6", "D6", "E6", "F6", "G6", "A6", "B6",
"C7", "D7", "E7", "F7", "G7", "A7", "B7",
]

# Instantiate the chime synthesizer with custom parameters
chime = Chime(
mixer.voice[0],
scale=brickscale,
material=Material.Brass, # SteelEMT, Ceramic, Wood, Copper, Aluminum, Brass
striker=Striker.HardWood, # Metal, Plexiglas, SoftWood, HardWood
voice=Voice.Tubular, # bell, perfect, tubular
scale_offset=-16
)

# Play scale notes sequentially
for index, note in enumerate(chime.scale):
chime.strike(note, 1.0)
time.sleep(0.1)
time.sleep(1)

def compare_n_channel_colors(color_1, color_2, tolerance=0):
"""Compares two integer multichannel count tuples using an unweighted linear
Euclidean difference. If the color value difference is within the tolerance
band of the reference, the method returns True.
The difference value index `tolerance` is used to detect color similarity.
Value range is an integer value from 0 to
(maximum_channel_count * number_of_channels). Default is 0 (detects a
single color value)."""
# Create list of channel deltas using list comprehension
deltas = [((color_1[idx] - count) ** 2) for idx, count in enumerate(color_2)]
# Resolve squared deltas to a Euclidean difference
# pylint: disable=c-extension-no-member
delta_color = math.sqrt(sum(deltas))
return bool(delta_color <= tolerance)

print("Bricktunes ready")


while True:
sensor_color = sensor.all_channels
# don't bother to check comparison when we're looking at a gap between bricks
if sensor_color[0] <= 70: # this checks for a minimum value on one channel
if gap_state is False:
print("no brick...")
for i in range(len(brick_color_names)):
brick_states[i] = False
gap_state = True

else:
if DEBUG:
print(sensor_color)
for i in range(len(brick_full_spectrum_values)):
color_match = compare_n_channel_colors(
sensor_color,
brick_full_spectrum_values[i],
TOLERANCE
)

if color_match is True:
if brick_states[i] is False:
for n in range(5):
chime.strike(chime.scale[i+(n*2)], 1.0)
time.sleep(0.1)
brick_states[i] = True
gap_state = False
print("sensor color:", sensor_color, "| ref:", brick_full_spectrum_values[i])
print(brick_color_names[i])
break
2 changes: 1 addition & 1 deletion Buckaroo_Plant_Care_Bot/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
text_group.append(motor_label)

clue_display.append(text_group)
board.DISPLAY.show(clue_display)
board.DISPLAY.root_group = clue_display

motor = DigitalInOut(board.P2)
motor.direction = Direction.OUTPUT
Expand Down
2 changes: 1 addition & 1 deletion CLUE_Altimeter/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

# create main display group
splash = displayio.Group()
clue.display.show(splash)
clue.display.root_group = splash

# background
bg_bmp, bg_pal = adafruit_imageload.load(
Expand Down
6 changes: 3 additions & 3 deletions CLUE_BBQ/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
title_label.y = 120
homescreen_screen.append(title_label)

clue.display.show(homescreen_screen)
clue.display.root_group = homescreen_screen

# Setup temperatures screen
temp_font = bitmap_font.load_font("/font/GothamBlack-25.bdf")
Expand Down Expand Up @@ -94,7 +94,7 @@

while True:
# re-display homescreen here
clue.display.show(homescreen_screen)
clue.display.root_group = homescreen_screen

print("Scanning...")
for adv in ble.start_scan(ProvideServicesAdvertisement, timeout=5):
Expand Down Expand Up @@ -146,7 +146,7 @@
"Probe", i + 1, "is unplugged",
)
my_labels[i].text = " ---"
clue.display.show(temperatures_screen)
clue.display.root_group = temperatures_screen

except _bleio.ConnectionError:
continue
2 changes: 1 addition & 1 deletion CLUE_BLE_Morse_Code/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
# Display Stuff
display = clue.display
disp_group = displayio.Group()
display.show(disp_group)
display.root_group = disp_group

# Background BMP with the Morse Code cheat sheet
bmp, pal = adafruit_imageload.load("morse_bg.bmp",
Expand Down
2 changes: 1 addition & 1 deletion CLUE_Dice_Roller/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
group.append(select_label)
group.append(roll_label)

board.DISPLAY.show(group)
board.DISPLAY.root_group = group

# Helper functions

Expand Down
2 changes: 1 addition & 1 deletion CLUE_Egg_Drop/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
splash.append(text_group)

# display everything so far
board.DISPLAY.show(splash)
board.DISPLAY.root_group = splash

# connect to the accelerometer
i2c = board.I2C() # uses board.SCL and board.SDA
Expand Down
2 changes: 1 addition & 1 deletion CLUE_Hand_Wash_Timer/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
text_group.append(timer_label)

clue_display.append(text_group)
clue.display.show(clue_display)
clue.display.root_group = clue_display

def countdown(seconds):
for i in range(seconds):
Expand Down
2 changes: 1 addition & 1 deletion CLUE_I_Ching/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@

# Set up main display group (splash)
splash = displayio.Group()
display.show(splash)
display.root_group = splash

# Add background and text label
splash.append(background)
Expand Down
10 changes: 5 additions & 5 deletions CLUE_Light_Painter/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def __init__(self, flip, path, tempfile, num_pixels, pixel_order,
if not self.images:
group = displayio.Group()
group.append(centered_label('NO IMAGES', 40, 3))
board.DISPLAY.show(group)
board.DISPLAY.root_group = group
while True:
pass

Expand Down Expand Up @@ -206,7 +206,7 @@ def load_image(self):
#self.rect = Rect(-board.DISPLAY.width, 120,
# board.DISPLAY.width, 40, fill=0x00B000)
#group.append(self.rect)
board.DISPLAY.show(group)
board.DISPLAY.root_group = group

# pylint: disable=eval-used
# (It's cool, is a 'trusted string' in the code)
Expand All @@ -227,7 +227,7 @@ def load_image(self):
except (MemoryError, BMPError):
group = displayio.Group()
group.append(centered_label('TOO BIG', 40, 3))
board.DISPLAY.show(group)
board.DISPLAY.root_group = group
sleep(4)

board.DISPLAY.show(displayio.Group()) # Clear display
Expand Down Expand Up @@ -330,7 +330,7 @@ def make_ui_group(self, main_config, config_label, rect_val=None):
# Config label always appears as last item in group
# so calling func can pop() and replace it if need be.
group.append(centered_label(config_label, 30 if rect_val else 40, 3))
board.DISPLAY.show(group)
board.DISPLAY.root_group = group
return group


Expand Down Expand Up @@ -365,7 +365,7 @@ def config_select(self, first_run=False):
if paint:
break # Exit loop, resume paint
else:
board.DISPLAY.show(group) # Put config UI back up
board.DISPLAY.root_group = group # Put config UI back up
elif action_right is RichButton.HOLD:
break
elif action_left is RichButton.TAP:
Expand Down
8 changes: 4 additions & 4 deletions CLUE_Metal_Detector/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import analogio
import ulab

from displayio import Group
from displayio import Group, CIRCUITPYTHON_TERMINAL
import terminalio

# These imports works on CLUE, CPB (and CPX on 5.x)
Expand Down Expand Up @@ -468,7 +468,7 @@ def sample_sum(pin, num):
magnet_circ_set(0)

# Start-up splash screen
display.show(screen_group)
display.root_group = screen_group

# Start-up splash screen
popup_text(show_text,
Expand Down Expand Up @@ -662,10 +662,10 @@ def sample_sum(pin, num):
if not screen_on or opt == 2: # Screen toggle
screen_on = not screen_on
if screen_on:
display.show(screen_group)
display.root_group = screen_group
display.brightness = 1.0
else:
display.show(None)
display.root_group = CIRCUITPYTHON_TERMINAL
display.brightness = 0.0
elif opt == 0: # Audio toggle
audio_on = not audio_on
Expand Down
2 changes: 1 addition & 1 deletion CLUE_Metronome/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
screen.append(increment_label)

# show the screen
clue.display.show(screen)
clue.display.root_group = screen


def metronome(accent): # Play metronome sound and flash display
Expand Down
2 changes: 1 addition & 1 deletion CLUE_Milk_Checker/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
splash.append(message)
splash.append(tvoc)
splash.append(eco2)
clue.display.show(splash)
clue.display.root_group = splash

# setup SGP30 and wait for initial warm up
i2c = board.I2C() # uses board.SCL and board.SDA
Expand Down
Loading

0 comments on commit 5e95fbf

Please sign in to comment.