69 lines
1.3 KiB
C++
69 lines
1.3 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() {
|
|
FadeInOut(0xff, 0x00, 0x00); // red
|
|
FadeInOut(0xff, 0xff, 0xff); // white
|
|
FadeInOut(0x00, 0x00, 0xff); // blue
|
|
}
|
|
|
|
void FadeInOut(byte red, byte green, byte blue){
|
|
float r, g, b;
|
|
|
|
for(int k = 0; k < 256; k=k+1) {
|
|
r = (k/256.0)*red;
|
|
g = (k/256.0)*green;
|
|
b = (k/256.0)*blue;
|
|
setAll(r,g,b);
|
|
showStrip();
|
|
}
|
|
|
|
for(int k = 255; k >= 0; k=k-2) {
|
|
r = (k/256.0)*red;
|
|
g = (k/256.0)*green;
|
|
b = (k/256.0)*blue;
|
|
setAll(r,g,b);
|
|
showStrip();
|
|
}
|
|
}
|
|
|
|
// *** 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();
|
|
} |