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
# | |
# wifi-preferred-network.py -- Given a list of preferred networks, | |
# connect to the one with the strongest signal | |
# for CircuitPython ESP32S2 Metro / MagTag | |
# 2020 @todbot / todbot.com/blog | |
import time | |
import wifi | |
from secrets import secrets |
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
# demo_ps2io.py -- simple demo of ps2io PS/2 keyboard library | |
# 2021 @todbot | |
# Tested on ESP32S2 Saola board and ItsyBitsy M4 running CircuitPython 6.2.0 | |
import board | |
# ESP32S2 Saola | |
#kbd = ps2io.Ps2(board.IO33, board.IO34) | |
# ItsyBitsy M4 | |
ps2_data_pin = board.D7 |
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
# play with seesaw encoder knob in CircuitPython | |
import board | |
from adafruit_seesaw.seesaw import Seesaw | |
from adafruit_seesaw.neopixel import NeoPixel | |
from adafruit_seesaw.digitalio import DigitalIO | |
ss_knob_base_addr = 0x36 | |
ss_switch_pin = 24 | |
ss_neopixel_pin = 6 |
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 array | |
def sine_wave(sample_frequency: float, pitch: float): | |
"""Generate a single sine wav cycle at the given sampling frequency and pitch.""" | |
length = int(sample_frequency / pitch) | |
b = array.array("H", [0] * length) | |
for i in range(length): | |
b[i] = int(math.sin(math.pi * 2 * i / length) * ((2 ** 15) - 1) + 2 ** 15) | |
return b |
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
# convert a dual pot "360 endless pot" aka sin/cos pot to angle position | |
# 17 Jun 2023 | |
# JP found these cool dual pots that act like endless rotary encoders, | |
# in a Elektron Samples box. They have two pots on a single shaft, | |
# one 90º out of phase. e.g. | |
# RV112FF-40-15A-0B20K - http://www.taiwanalpha.com/downloads?target=products&id=79 | |
# | |
# see: https://forum.pjrc.com/threads/59830-Read-Endless-Potentiometer | |
# answer: float angle = atan2f(potA, potB) | |
# |