Created
August 2, 2017 19:27
-
-
Save hovissimo/fdbda05d9b0ea63b797b4bcd7960b66d 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
#include <Adafruit_NeoPixel.h> | |
#define PIN 6 | |
#define NUMPIXELS 112 | |
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); | |
void setup() { | |
pixels.begin(); | |
pixels.show(); // Initialize all pixels to 'off' | |
} | |
void loop() { | |
rainbowCycle(20); | |
delay(250); | |
} | |
// Slightly different, this makes the rainbow equally distributed throughout | |
void rainbowCycle(uint8_t wait) { | |
uint16_t i, j; | |
int strands[] = {20, 21, 19, 19, 20, 13}; | |
// 6 strands | |
for (int i = 0; i < 6; i++) { | |
for (int p = 0; p < strands[i]; p++) { | |
pixels.setPixelColor(p, Wheel(((i * 256 / pixels.numPixels()) + j) & 255)); | |
pixels.show(); | |
delay(250); | |
} | |
} | |
} | |
// 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 pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3); | |
} | |
if (WheelPos < 170) { | |
WheelPos -= 85; | |
return pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3); | |
} | |
WheelPos -= 170; | |
return pixels.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