Skip to content

Instantly share code, notes, and snippets.

View gallaugher's full-sized avatar

Gallaugher gallaugher

View GitHub Profile
@gallaugher
gallaugher / toggle_dashboard.py
Created November 11, 2026 20:07
toggle_dashboard.py
# adafruit_dashboard.py
import board, neopixel, os, ssl, socketpool, wifi
import adafruit_minimqtt.adafruit_minimqtt as MQTT
# set up the NeoPixel strand
strand = neopixel.NeoPixel(board.GPIO15, 256, brightness=0.2)
RED = (255, 0, 0); BLACK = (0, 0, 0); BLUE = (0, 0, 255); GREEN = (0, 255, 0)
strand.fill(BLACK)
@gallaugher
gallaugher / dashboard_color.py
Created November 11, 2026 19:59
adafruit io dashboard with on off and color picker
# dashboard_color.py
# The connection function will read the feed's last value & sync
# the build according to that value.
import board, neopixel, os, ssl, socketpool, wifi
import adafruit_minimqtt.adafruit_minimqtt as MQTT
# set up the NeoPixel strand
strand = neopixel.NeoPixel(board.GPIO15, 256, brightness=0.2)
RED = (255, 0, 0); BLACK = (0, 0, 0); BLUE = (0, 0, 255); GREEN = (0, 255, 0)
strand.fill(BLACK)
@gallaugher
gallaugher / ESP32_npt_time.py
Created November 11, 2026 17:55
ESP32 CircuitPython NTP Time
# ntp_clock.py
import board, time, os, wifi, socketpool, rtc
import adafruit_ntp
UTC_OFFSET_HOURS = int(os.getenv("UTC_OFFSET_HOURS", "-5")) # -5 = Boston in winter
RESYNC_HOUR = 3 # once a day, at 3 AM, ask again so the clock doesn't drift
# settings.toml connects to Wi-Fi at boot; this only runs if that didn't happen
if not wifi.radio.connected:
wifi.radio.connect(os.getenv("CIRCUITPY_WIFI_SSID"),
@gallaugher
gallaugher / ListView.swift
Created November 9, 2026 17:41
SwiftData ListView Template
import SwiftUI
import SwiftData
struct ListView: View {
@Query private var guests: [Guest] // every saved Guest (or the preview sample data in the canvas)
@State private var sheetIsPresented = false
@Environment(\.modelContext) private var modelContext // the "desk" where we add and delete
var body: some View {
NavigationStack {
@gallaugher
gallaugher / MockData.swift
Created November 9, 2026 17:22
MockData Extension
// Sample data for the Preview canvas only. It lives in memory, never on the device.
// You'll need to change values for the Class and class properties, and the data you pass in.
extension Guest {
@MainActor
static var preview: ModelContainer {
do {
let container = try ModelContainer(for: Guest.self, configurations: ModelConfiguration(isStoredInMemoryOnly: true))
container.mainContext.insert(Guest(name: "Snoop", item: "Brownies"))
container.mainContext.insert(Guest(name: "Travis Kelce", item: "Ribs"))
container.mainContext.insert(Guest(name: "Taylor Swift", item: "Cheese Steaks"))
@gallaugher
gallaugher / DetailView.swift
Last active November 9, 2026 22:51
FriendsGiving app DetailView.swift
//
// DetailView.swift
// FriendsGiving
//
// Created by John Gallaugher on 11/9/26.
//
import SwiftUI
import SwiftData
@gallaugher
gallaugher / touch_piano_esp32.py
Created October 28, 2026 19:07
touch_piano_esp32.py
# touch_piano_esp32.py
import board, busio, time, audiobusio, synthio
import adafruit_mpr121
# I2S DAC wiring: WSEL -> GPIO16, DIN -> GPIO17, BCK -> GPIO18
audio = audiobusio.I2SOut(bit_clock=board.GPIO18, word_select=board.GPIO16, data=board.GPIO17)
synth = synthio.Synthesizer(sample_rate=22050)
audio.play(synth) # silent until a note is pressed
# Middle octave: pad 0 = C4 (middle C), pad 1 = C#4 ... pad 11 = B4
@gallaugher
gallaugher / tone_test_esp32.py
Created October 28, 2026 19:03
tone_test_esp32.py
# tone_test_esp32.py
import board, time, audiobusio, synthio
# I2S DAC wiring: WSEL -> GPIO16, DIN -> GPIO17, BCK -> GPIO18
audio = audiobusio.I2SOut(bit_clock=board.GPIO18, word_select=board.GPIO16, data=board.GPIO17)
synth = synthio.Synthesizer(sample_rate=22050)
audio.play(synth) # the synth is now "playing" but silent until a note is pressed
# The middle octave: C4 (middle C) up to B4. One frequency (Hz) per key, in order
note_names = ["C4", "C#4", "D4", "D#4", "E4", "F4", "F#4", "G4", "G#4", "A4", "A#4", "B4"]
@gallaugher
gallaugher / funky_fingers_esp32.py
Created October 28, 2026 18:59
funky_fingers_esp32.py
# funky_fingers_esp32.py
import board, busio, time, audiobusio
import adafruit_mpr121
from audiocore import WaveFile
# I2S DAC wiring: WSEL -> GPIO16, DIN -> GPIO17, BCK -> GPIO18
audio = audiobusio.I2SOut(bit_clock=board.GPIO18, word_select=board.GPIO16, data=board.GPIO17)
path = "funky/"
loops = ["full_drum_loop_128bpm.wav", "big_boom_loop_1_c_128bpm.wav",
"drum_buildup_12_128bpm.wav", "drum_loop_3_128bpm.wav",
@gallaugher
gallaugher / two_buttons_two_sounds_esp32.py
Created October 28, 2026 18:49
two_buttons_two_sounds_esp32.py
# two_buttons_two_sounds_esp32.py
import board, digitalio, audiobusio
from audiomp3 import MP3Decoder
# I2S DAC wiring: WSEL -> GPIO16, DIN -> GPIO17, BCK -> GPIO18
audio = audiobusio.I2SOut(bit_clock=board.GPIO18, word_select=board.GPIO16, data=board.GPIO17)
path = "sounds/"
decoder = MP3Decoder(path + "nice-job-maker.mp3") # create ONCE, with a real file
def play_mp3(filename):