88 lines
1.7 KiB
C++
88 lines
1.7 KiB
C++
#include "FastLED.h"
|
|
#define NUM_LEDS 60
|
|
CRGB leds[NUM_LEDS];
|
|
#define PIN 6
|
|
|
|
void setup()
|
|
{
|
|
FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
|
|
}
|
|
|
|
// *** REPLACE FROM HERE ***
|
|
void loop() {
|
|
theaterChaseRainbow(50);
|
|
}
|
|
|
|
void theaterChaseRainbow(int SpeedDelay) {
|
|
byte *c;
|
|
|
|
for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
|
|
for (int q=0; q < 3; q++) {
|
|
for (int i=0; i < NUM_LEDS; i=i+3) {
|
|
c = Wheel( (i+j) % 255);
|
|
setPixel(i+q, *c, *(c+1), *(c+2)); //turn every third pixel on
|
|
}
|
|
showStrip();
|
|
|
|
delay(SpeedDelay);
|
|
|
|
for (int i=0; i < NUM_LEDS; i=i+3) {
|
|
setPixel(i+q, 0,0,0); //turn every third pixel off
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
byte * Wheel(byte WheelPos) {
|
|
static byte c[3];
|
|
|
|
if(WheelPos < 85) {
|
|
c[0]=WheelPos * 3;
|
|
c[1]=255 - WheelPos * 3;
|
|
c[2]=0;
|
|
} else if(WheelPos < 170) {
|
|
WheelPos -= 85;
|
|
c[0]=255 - WheelPos * 3;
|
|
c[1]=0;
|
|
c[2]=WheelPos * 3;
|
|
} else {
|
|
WheelPos -= 170;
|
|
c[0]=0;
|
|
c[1]=WheelPos * 3;
|
|
c[2]=255 - WheelPos * 3;
|
|
}
|
|
|
|
return c;
|
|
}
|
|
// *** REPLACE TO HERE ***
|
|
|
|
void showStrip() {
|
|
#ifdef ADAFRUIT_NEOPIXEL_H
|
|
// NeoPixel
|
|
strip.show();
|
|
#endif
|
|
#ifndef ADAFRUIT_NEOPIXEL_H
|
|
// FastLED
|
|
FastLED.show();
|
|
#endif
|
|
}
|
|
|
|
void setPixel(int Pixel, byte red, byte green, byte blue) {
|
|
#ifdef ADAFRUIT_NEOPIXEL_H
|
|
// NeoPixel
|
|
strip.setPixelColor(Pixel, strip.Color(red, green, blue));
|
|
#endif
|
|
#ifndef ADAFRUIT_NEOPIXEL_H
|
|
// FastLED
|
|
leds[Pixel].r = red;
|
|
leds[Pixel].g = green;
|
|
leds[Pixel].b = blue;
|
|
#endif
|
|
}
|
|
|
|
void setAll(byte red, byte green, byte blue) {
|
|
for(int i = 0; i < NUM_LEDS; i++ ) {
|
|
setPixel(i, red, green, blue);
|
|
}
|
|
showStrip();
|
|
} |