-
-
Save pennig/003a0c7d46ae88d54b35 to your computer and use it in GitHub Desktop.
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
#include "neopixel/neopixel.h" | |
SYSTEM_MODE(AUTOMATIC); | |
#define PIXEL_TYPE WS2812B | |
Adafruit_NeoPixel strip = Adafruit_NeoPixel(11, D2, PIXEL_TYPE); | |
void rainbow(Adafruit_NeoPixel, uint8_t); | |
uint32_t Wheel(Adafruit_NeoPixel, byte); | |
void setup() | |
{ | |
strip.begin(); | |
strip.show(); // Initialize all pixels to 'off' | |
} | |
void loop() | |
{ | |
rainbow(strip, 20); | |
} | |
void rainbow(Adafruit_NeoPixel s, uint8_t wait) { | |
uint16_t i, j; | |
for(j=0; j<256; j++) { | |
for(i=0; i<s.numPixels(); i++) { | |
s.setPixelColor(i, Wheel(s, (i+j) & 255)); | |
} | |
s.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(Adafruit_NeoPixel s, byte WheelPos) { | |
if(WheelPos < 85) { | |
return s.Color(WheelPos * 3, 255 - WheelPos * 3, 0); | |
} else if(WheelPos < 170) { | |
WheelPos -= 85; | |
return s.Color(255 - WheelPos * 3, 0, WheelPos * 3); | |
} else { | |
WheelPos -= 170; | |
return s.Color(0, WheelPos * 3, 255 - WheelPos * 3); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment