Created
September 13, 2025 00:45
-
-
Save philipturner/74579bf0ccc845478f56cf372457cc6a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /* Analog Control RGB LED Color, Teensyduino Tutorial #4 | |
| http://www.pjrc.com/teensy/tutorial4.html | |
| This example code is in the public domain. | |
| */ | |
| // TODO: Save to GitHub gist | |
| const int outPin = 12; | |
| void setup() { | |
| pinMode(outPin, OUTPUT); | |
| analogWriteResolution(14); | |
| delay(1000); // Delay in ms to set up the camera. | |
| } | |
| // 3.299 V when in standby mode | |
| // 3.297 V when running a program | |
| float calibrated_3_3V = 3.294; | |
| int16_t counter = 32; | |
| // 28 Hz lowpass on 9.2 kHz PWM output | |
| // - 5.56 μF -> 5.60 μF after 10 s dielectric absorption | |
| // (sort of like piezoelectric creep for electrolytics) | |
| // 5.67 μF -> 5.62 μF (changes with configuration) | |
| // - 1 kΩ | |
| // - Engineered in an attempt to stabilize the | |
| // multimeter's DC voltage reading. | |
| void loop() | |
| { | |
| float desiredVoltage = float(counter) / 10; | |
| float normalizedValue = desiredVoltage / calibrated_3_3V; | |
| int16_t quantized_10unorm = int16_t(normalizedValue * 16384); | |
| analogWrite(outPin, quantized_10unorm); | |
| if (counter > 0) { | |
| counter -= 1; | |
| } | |
| // Delay in ms before next loop iteration. | |
| delay(1000); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment