82 lines
1.5 KiB
C++
82 lines
1.5 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() {
|
|
rainbowCycle(20);
|
|
}
|
|
|
|
void rainbowCycle(int SpeedDelay) {
|
|
byte *c;
|
|
uint16_t i, j;
|
|
|
|
for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
|
|
for(i=0; i< NUM_LEDS; i++) {
|
|
c=Wheel(((i * 256 / NUM_LEDS) + j) & 255);
|
|
setPixel(i, *c, *(c+1), *(c+2));
|
|
}
|
|
showStrip();
|
|
delay(SpeedDelay);
|
|
}
|
|
}
|
|
|
|
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();
|
|
} |