Skip to content

Instantly share code, notes, and snippets.

View gallaugher's full-sized avatar

Gallaugher gallaugher

View GitHub Profile
@gallaugher
gallaugher / code.py
Last active February 19, 2025 18:36
Should_stop_when_button_B_held_and_song_ends
# sasa-chairs
# Note: This was demo code set up to show students how the debounced button press doesn't register until
# after the song plays. However for some reason I notice when run on a CPB using CircuitPython 9.2.4
# that the song runs a second time, even after the update() has run, the button_B is pressed, and
# button_A: False, button_B: False prints <- not expected because my finger remains on button_B.
# Here is some sample output. I'm seeing that even after False / False, the sound play restarts & am unsure why.
# If I continue holding button_B through one more play, the sound stops, as expected, and button_B.value is True
# but I had expected this to occur earlier when I held B through the first complete sound play.
# If you'd like to test with my sound, it's in the sasa-chairs folder at:
# http://bit.ly/circuitpython-school-files
import board, digitalio
led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT
print("CircuitPython is Awesome!")
while True:
led.value = True
@gallaugher
gallaugher / code.py
Created November 20, 2024 16:24
Raspberry Pi Pico W Robot Code
# MQTT Raspberry Pi Pico W Robot with Adafruit IO & CircuitPython
# Include movement & sounds
# YouTube tutorial at https://bit.ly/pico-tutorials
# MQTT With Color Picker, Sound & Servo - Adafruit IO
import board, time, pwmio, mount_sd
import os, ssl, socketpool, wifi
import adafruit_minimqtt.adafruit_minimqtt as MQTT
from audiopwmio import PWMAudioOut as AudioOut
from audiomp3 import MP3Decoder
from adafruit_motor import servo
@gallaugher
gallaugher / config.h
Created August 9, 2024 03:44
config for uncanny eyes & Itsy Bitsy
// Pin selections here are based on the original Adafruit Learning System
// guide for the Teensy 3.x project. Some of these pin numbers don't even
// exist on the smaller SAMD M0 & M4 boards, so you may need to make other
// selections:
// GRAPHICS SETTINGS (appearance of eye) -----------------------------------
// If using a SINGLE EYE, you might want this next line enabled, which
// uses a simpler "football-shaped" eye that's left/right symmetrical.
// Default shape includes the caruncle, creating distinct left/right eyes.
@gallaugher
gallaugher / audiomixer-drum-macahine.py
Created July 30, 2024 23:54
audiomixer-drum-macahine.py
# audiomixer-drum-machine.py
import board, time, digitalio, touchio
import audiomixer, audiocore
try:
from audioio import AudioOut
except ImportError:
try:
from audiopwmio import PWMAudioOut as AudioOut
except ImportError:
print("This board does not support audio")
@gallaugher
gallaugher / audio-without-pops.py
Created July 30, 2024 21:33
audio-without-pops.py
import board, time, digitalio
import audiomixer, audiocore
from audiopwmio import PWMAudioOut as AudioOut
# Speaker setup for the CircuitPlayground boards (not for Pico)
speaker = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
speaker.direction = digitalio.Direction.OUTPUT
speaker.value = True
# use speaker location to create an AudioOut object named audio
@gallaugher
gallaugher / capacitive-touch.py
Created July 24, 2024 17:14
Capacitive Touch CircuitPython
# capacitive-touch.py
import board, neopixel, time, digitalio, touchio
from adafruit_led_animation.color import RED, YELLOW, ORANGE, \
GREEN, TEAL, CYAN, BLUE, PURPLE, MAGENTA, GOLD, PINK, AQUA, \
JADE, AMBER, OLD_LACE, WHITE, BLACK
from audiocore import WaveFile
try:
from audioio import AudioOut
except ImportError:
try:
@gallaugher
gallaugher / cpb-neopixels.py
Created June 4, 2024 23:07
cpb-neopixels.py
# Turn on CircuitPlayground's NeoPixels, 1 at a time,
# then turn them off one at a time in the opposite direction
import time, board, neopixel
# Create the object named pixels so we can work with the CPB's lights
pixels = neopixel.NeoPixel(board.NEOPIXEL, 10)
# Define the colors named BLUE and BLACK
BLUE = (0, 0, 255)
BLACK = (0, 0, 0)
@gallaugher
gallaugher / cp-blink.py
Last active January 12, 2025 01:23
cp-blink.py
@gallaugher
gallaugher / PreviewContainer.swift
Created February 14, 2024 10:04
PreviewContainer.swift
import Foundation
import SwiftData
class PreviewContainer {
let container: ModelContainer! // register the container
init(_ types: [any PersistentModel.Type], isStoredInMemoryOnly: Bool = true) {
let schema = Schema(types) // should be able to pass in any schema & have them registered
let config = ModelConfiguration(isStoredInMemoryOnly: isStoredInMemoryOnly)
self.container = try! ModelContainer(for: schema, configurations: [config])