Skip to content

Instantly share code, notes, and snippets.

@nateinaction
Last active April 16, 2021 23:04
Show Gist options
  • Save nateinaction/bccb3b4690a2983283789f6bf38834ef to your computer and use it in GitHub Desktop.
Save nateinaction/bccb3b4690a2983283789f6bf38834ef to your computer and use it in GitHub Desktop.
Danielle's Carlsbad Caverns Light
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
#define NUMPIXELS 8
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
pixels.begin();
pixels.show();
}
// Starting off with multiple colors
int offset = 96;
void loop() {
int wait = 100;
int colorSteps = 256;
if(offset > colorSteps) {
// Turn off after an hour
colorWipe(pixels.Color(0, 0, 0));
} else {
rainbow(wait, colorSteps, offset);
offset++;
}
}
// Set all the pixels to a certain color
void colorWipe(uint32_t color) {
for(int i = 0; i < pixels.numPixels(); i++) {
pixels.setPixelColor(i, color);
pixels.show();
}
}
// Rainbow cycles pixel 1 and 8 in a rainbow pattern
// pixel 8 advances one additional color step per cycle
// so that all colors may be displayed together at least once
// every 256 loops.
// Every loop takes 25.6 seconds with all loops taking 34.6 minutes to complete
void rainbow(int wait, int colorSteps, int secondPixelOffset) {
int currentColor = 0;
int colorRange = 65536;
for(int pixelHue = 0; pixelHue < colorRange; pixelHue += colorSteps) {
pixels.setPixelColor(0, pixels.gamma32(pixels.ColorHSV(pixelHue)));
int secondPixelHue = pixelHue + (secondPixelOffset * colorRange / colorSteps);
pixels.setPixelColor(pixels.numPixels() - 1, pixels.gamma32(pixels.ColorHSV(secondPixelHue)));
pixels.show(); // Update pixels with new contents
delay(wait);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment