Skip to content

Instantly share code, notes, and snippets.

View pingswept's full-sized avatar

Brandon Stafford pingswept

  • Tufts University
  • Somerville, Massachusetts, USA
View GitHub Profile
@pingswept
pingswept / gist:870d40ea8b82203dbe1bbebb2321b5dc
Created November 24, 2025 19:28
analog meter test code, ME 30 example fall 2025
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
"""
This test will initialize the display using displayio and draw a solid green
background, a smaller purple rectangle, and some yellow text.
"""
import analogio
import board
@pingswept
pingswept / state_machine_exercise-28.py
Last active November 3, 2025 17:47
another state machine example
import board
import analogio as aio
import digitalio as dio
import pwmio
import time
cw = pwmio.PWMOut(board.D6, frequency=500, duty_cycle=0)
ccw = pwmio.PWMOut(board.D8, frequency=500, duty_cycle=0)
motor = cw
@pingswept
pingswept / state_machine_exercise-27.py
Last active November 3, 2025 21:56
state machine example
import board
import digitalio as dio
import time
motor_cw = dio.DigitalInOut(board.D3)
motor_cw.direction = dio.Direction.OUTPUT
motor_ccw = dio.DigitalInOut(board.D4)
motor_ccw.direction = dio.Direction.OUTPUT
@pingswept
pingswept / test-dragon-tail.py
Created January 8, 2023 21:43
Python code to light up a dragon's tail made of LEDs that attaches to the back of my bike.
import time
import board
import neopixel
import random
# The number of NeoPixels
num_pixels = 240
# The order of the pixel colors - RGB or GRB. Some NeoPixels have red and green reversed!
# For RGBW NeoPixels, simply change the ORDER to RGBW or GRBW.
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(('', 5000))
while True:
data, addr = sock.recvfrom(4096)
print('got packet: %s from $s' % data, addr)
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto(b"Buy a copy of Chip War today!", ("130.64.80.187", 5000))
import board
import digitalio as dio
import time
led = dio.DigitalInOut(board.LED)
led.direction = dio.Direction.OUTPUT
button = dio.DigitalInOut(board.D6)
button.direction = dio.Direction.INPUT
@pingswept
pingswept / state-machine.py
Last active November 1, 2022 13:25
State machine example for ME 30 at Tufts
import board
import digitalio as dio
import time
led = dio.DigitalInOut(board.LED)
led.direction = dio.Direction.OUTPUT
button = dio.DigitalInOut(board.D6)
button.direction = dio.Direction.INPUT
sudo iwlist wlan0 scan essid Tufts_Secure
wlan0 Scan completed :
Cell 01 - Address: 70:DB:98:14:69:FF
Channel:52
Frequency:5.26 GHz (Channel 52)
Quality=70/70 Signal level=-39 dBm
Encryption key:off
ESSID:"Tufts_Wireless"
Bit Rates:12 Mb/s; 18 Mb/s; 24 Mb/s; 36 Mb/s; 48 Mb/s
54 Mb/s
@pingswept
pingswept / fabfile.py
Created March 16, 2021 15:30
Fabric demo
from fabric import task
# Usage
#
# fab -H [email protected] --prompt-for-login-password deploy
@task
def deploy(c):
hostname = c.run('hostname', hide=True).stdout
print('\033[32;1mLogged into {0}\033[0m'.format(hostname))