Skip to content

Instantly share code, notes, and snippets.

View gallaugher's full-sized avatar

Gallaugher gallaugher

View GitHub Profile
@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
Created June 4, 2024 19:54
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])
// countriesAndFlags is a dictionary of country names : flag emojis
// countries is a String array of country names in alphabetical order
struct Constants {
static let countriesAndFlags = ["Afghanistan": "🇦🇫",
"Åland Islands": "🇦🇽",
"Albania": "🇦🇱",
"Algeria": "🇩🇿",
"American Samoa": "🇦🇸",
@gallaugher
gallaugher / code.py
Created April 5, 2023 15:33
Playback from Adafruit IO - button sound crashes on third interrupted playback
# MQTT With Color Picker - Adafruit I0
import board, time, neopixel
import os, ssl, socketpool, wifi
import adafruit_minimqtt.adafruit_minimqtt as MQTT
# import lines for audio & mp3 playing
from audiopwmio import PWMAudioOut as AudioOut
from audiomp3 import MP3Decoder
# setup the speaker
audio = AudioOut(board.GP16) # assuming tip of speaker attached to GP16
@gallaugher
gallaugher / mount_sd.py
Created March 3, 2023 00:37
mount_sd.py
# mount_sd.py
import board, busio, sdcardio, storage
# setup pins for SPI
sck = board.GP10 # yellow
si = board.GP11 # blue
so = board.GP12 # green
cs = board.GP13 # yellow
spi = busio.SPI(sck, si, so)
sdcard = sdcardio.SDCard(spi, cs)