Skip to content

Instantly share code, notes, and snippets.

@dupontgu
dupontgu / code.py
Created May 12, 2023 18:42
CircuitPython demo showing how to reduce ADC "flickering" when reading potentiometer
import board
import time
from analogio import AnalogIn
analog_in = AnalogIn(board.A0)
pot_v_9bit = analog_in.value >> 7
pot_v_7bit = pot_v_9bit >> 2
while True:
# take a few readings and average them for a tiny bit of filtering
@dupontgu
dupontgu / code.py
Created November 16, 2022 14:23
CircuitPython HTTP Remote (used for Android TV control)
# Tested on a Raspbery Pi Pico W running CircuitPyton 8
import socketpool
import wifi
import board
import array
import time
import usb_hid
import digitalio
@dupontgu
dupontgu / freezer_esp32.ino
Created November 14, 2020 00:40
ESP-32 Arduino code to accompany Freezer Door Alarm project: https://hackaday.io/project/175862-quick-n-dirty-freezer-door-alarm
/**
*
* ESP-32 code to accompany freezer door alarm project:
* https://hackaday.io/project/175862-quick-n-dirty-freezer-door-alarm
* by Guy Dupont - @dupontgu (GitHub)
*
* tl;dr
* Periodically check switch. If open for two consecutive checks, connect to Wi-Fi and make web request.
*
**/
@dupontgu
dupontgu / ReaScriptWebhook.eel
Last active July 6, 2021 13:44
ReaScript that triggers actions on IFTTT based on when you start and stop recording in Reaper
turnLightOn = "/bin/sh -c \"curl -H 'Connection: close' -i -X POST 'https://maker.ifttt.com/trigger/record_lamp_on/with/key/your_key_here'\"";
turnLightOff = "/bin/sh -c \"curl -H 'Connection: close' -i -X POST 'https://maker.ifttt.com/trigger/record_lamp_off/with/key/your_key_here'\"";
lastState = 0;
function main()
(
currentState = GetPlayState() & 4;
lastState != currentState ? (
command = currentState > 0 ? turnLightOn : turnLightOff;
ExecProcess(#result, command, 0);
@dupontgu
dupontgu / UnitTestFileReader.kt
Created April 9, 2019 15:44
Read raw file for Android unit tests
class BaseTest {
// assuming fileName is the full name of a file in /test/resources
protected fun readFile(fileName:String) : String {
javaClass.classLoader?.getResourceAsStream(fileName)?.let {
val result = ByteArrayOutputStream()
val buffer = ByteArray(1024)
var length = it.read(buffer)
while (length != -1) {
result.write(buffer, 0, length)
length = it.read(buffer)