Skip to content

Instantly share code, notes, and snippets.

@MatthiasKainer
Created April 14, 2019 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MatthiasKainer/0324ed3bf0aad8319abb4d5ddd1410d9 to your computer and use it in GitHub Desktop.
Save MatthiasKainer/0324ed3bf0aad8319abb4d5ddd1410d9 to your computer and use it in GitHub Desktop.
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 4
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.setBrightness(20);
strip.show(); // Initialize all pixels to 'off'
delay(30);
colorWipe(strip.Color(255, 0, 0), 10); // Red
colorWipe(strip.Color(0, 255, 0), 10); // Green
colorWipe(strip.Color(0, 0, 255), 10); // Blue
colorWipe(strip.Color(255, 255, 255), 10); // White
rainbowStart(10);
}
void loop() {
rainbowCycle(20);
}
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
// From the colorWipe boot sequence, start the rainbow
void rainbowStart(uint8_t wait) {
uint16_t i, j;
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + 256*5-1) & 255));
strip.show();
delay(wait);
}
}
// cycle the rainbow
void rainbowCycle(uint8_t wait) {
uint16_t i, j;
for(j=256*5-1; j>=0; j--) { // 5 cycles of all colors on wheel
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment