This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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": "🇦🇸", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Idea based on original code by @todbot | |
# Modified (probably poorly) by Prof. John Gallaugher to include | |
# This version tested with CircuitPython v.8 | |
import board, adafruit_mpr121, time, audiomixer, audiocore | |
import mount_sd | |
from audiocore import WaveFile | |
from audiopwmio import PWMAudioOut as AudioOut | |
# Setup i2c on the Pico w/STEMMA_QT wired as shown in the diagram - GP4 (SDA/Blue), GP5 (SCL/Yellow, Power 3.3v(Out) Red | |
i2c = board.STEMMA_I2C() # Same for any board w/built-in STEMMA_QT port |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# audiomixer_demo.py -- show how to fade up and down playing loops | |
import time, board, audiocore, audiomixer, adafruit_mpr121, digitalio | |
from audiomp3 import MP3Decoder | |
# import PWMAudioOut & name it AudioOut | |
from audiopwmio import PWMAudioOut as AudioOut | |
# set up I2C | |
i2c = board.STEMMA_I2C() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This code assumes Asset catalog has an image file named "logo" | |
// also assumes that the first View returned after successful login is called "ListView" | |
// After pasting this, be sure you update the "App" file so that it loads | |
// LoginView as the first View. | |
import SwiftUI | |
import Firebase | |
struct LoginView: View { | |
enum Field { | |
case email, password |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# paho MQTT test | |
import paho.mqtt.client as mqtt | |
# The callback for when the client receives a CONNACK response from the server. | |
def on_connect(client, userdata, flags, rc): | |
print("Connected with result code "+str(rc)) | |
# Subscribing in on_connect() means that if we lose the connection and | |
# reconnect then subscriptions will be renewed. | |
client.subscribe("$SYS/#") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sound | |
import time, board, digitalio | |
from audiocore import WaveFile | |
try: | |
from audioio import AudioOut | |
except ImportError: | |
try: | |
from audiopwmio import PWMAudioOut as AudioOut | |
except ImportError: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from adafruit_led_animation.color import ( | |
AMBER, #(255, 100, 0) | |
AQUA, # (50, 255, 255) | |
BLACK, #OFF (0, 0, 0) | |
BLUE, # (0, 0, 255) | |
CYAN, # (0, 255, 255) | |
GOLD, # (255, 222, 30) | |
GREEN, # (0, 255, 0) | |
JADE, # (0, 255, 40) | |
MAGENTA, #(255, 0, 20) |
NewerOlder