Created
October 29, 2021 21:28
-
-
Save stonehippo/57cf98f60e35a1d4bc91a5af5bb2d763 to your computer and use it in GitHub Desktop.
Carved gourd/pumpkin flicker with an Arduino and NeoPixels.
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
// A simple pumpkin/gourd flicker light | |
// Written by 2021 George White (stonehippo@gmail.com) | |
// This code is in the public domain | |
// | |
// I built this to power a little carved gourd for a company function. | |
// I ran it on an Adafruit Trinket 3.3V with two NeoPixels dots, but it | |
// should work on pretty much any Arduino-compatible board. The main | |
// thing you'd have to change it the PIXEL_PIN. | |
#define PIXEL_PIN 0 | |
#define MAX 127 | |
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(2, PIXEL_PIN, NEO_GRBW + NEO_KHZ800); | |
void setup() { | |
pixels.begin(); | |
pixels.setBrightness(120); | |
} | |
void loop() { | |
setEye(0); | |
setEye(1); | |
delay(random(80,150)); | |
} | |
void setEye(int eye) { | |
pixels.setPixelColor(eye, eyeColor()); | |
pixels.show(); | |
} | |
uint32_t eyeColor() { | |
int hue; | |
// flip a coin on direction from pure red | |
if (random(0,1) == 0) { | |
hue = random(0,1000); | |
} else { | |
hue = random(64335,65335); | |
} | |
int sat = random(50,255); | |
int value = random(25,127); | |
return pixels.gamma32(pixels.ColorHSV(hue, sat, value)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment