Add fast led demo
This commit is contained in:
commit
cbc83b9aab
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
* Hack to enable SK6812 RGBW strips to work with FastLED.
|
||||||
|
*
|
||||||
|
* Original code by Jim Bumgardner (http://krazydad.com).
|
||||||
|
* Modified by David Madison (http://partsnotincluded.com).
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FastLED_RGBW_h
|
||||||
|
#define FastLED_RGBW_h
|
||||||
|
|
||||||
|
struct CRGBW {
|
||||||
|
union {
|
||||||
|
struct {
|
||||||
|
union {
|
||||||
|
uint8_t g;
|
||||||
|
uint8_t green;
|
||||||
|
};
|
||||||
|
union {
|
||||||
|
uint8_t r;
|
||||||
|
uint8_t red;
|
||||||
|
};
|
||||||
|
union {
|
||||||
|
uint8_t b;
|
||||||
|
uint8_t blue;
|
||||||
|
};
|
||||||
|
union {
|
||||||
|
uint8_t w;
|
||||||
|
uint8_t white;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
uint8_t raw[4];
|
||||||
|
};
|
||||||
|
|
||||||
|
CRGBW(){}
|
||||||
|
|
||||||
|
CRGBW(uint8_t rd, uint8_t grn, uint8_t blu, uint8_t wht){
|
||||||
|
r = rd;
|
||||||
|
g = grn;
|
||||||
|
b = blu;
|
||||||
|
w = wht;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void operator = (const CRGB c) __attribute__((always_inline)){
|
||||||
|
this->r = c.r;
|
||||||
|
this->g = c.g;
|
||||||
|
this->b = c.b;
|
||||||
|
this->white = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
inline uint16_t getRGBWsize(uint16_t nleds){
|
||||||
|
uint16_t nbytes = nleds * 4;
|
||||||
|
if(nbytes % 3 > 0) return nbytes / 3 + 1;
|
||||||
|
else return nbytes / 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,70 @@
|
||||||
|
/*
|
||||||
|
* Example sketch using FastLED for RGBW strips (SK6812). Includes
|
||||||
|
* color wipes and rainbow pattern.
|
||||||
|
*
|
||||||
|
* Written by David Madison
|
||||||
|
* http://partsnotincluded.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "FastLED.h"
|
||||||
|
#include "FastLED_RGBW.h"
|
||||||
|
|
||||||
|
#define NUM_LEDS 60
|
||||||
|
#define DATA_PIN 6
|
||||||
|
|
||||||
|
CRGBW leds[NUM_LEDS];
|
||||||
|
CRGB *ledsRGB = (CRGB *) &leds[0];
|
||||||
|
|
||||||
|
const uint8_t brightness = 128;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
FastLED.addLeds<WS2812B, DATA_PIN, RGB>(ledsRGB, getRGBWsize(NUM_LEDS));
|
||||||
|
FastLED.setBrightness(brightness);
|
||||||
|
FastLED.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop(){
|
||||||
|
colorFill(CRGB::Red);
|
||||||
|
colorFill(CRGB::Green);
|
||||||
|
colorFill(CRGB::Blue);
|
||||||
|
fillWhite();
|
||||||
|
rainbowLoop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void colorFill(CRGB c){
|
||||||
|
for(int i = 0; i < NUM_LEDS; i++){
|
||||||
|
leds[i] = c;
|
||||||
|
FastLED.show();
|
||||||
|
delay(50);
|
||||||
|
}
|
||||||
|
delay(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fillWhite(){
|
||||||
|
for(int i = 0; i < NUM_LEDS; i++){
|
||||||
|
leds[i] = CRGBW(0, 0, 0, 255);
|
||||||
|
FastLED.show();
|
||||||
|
delay(50);
|
||||||
|
}
|
||||||
|
delay(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
void rainbow(){
|
||||||
|
static uint8_t hue;
|
||||||
|
|
||||||
|
for(int i = 0; i < NUM_LEDS; i++){
|
||||||
|
leds[i] = CHSV((i * 256 / NUM_LEDS) + hue, 255, 255);
|
||||||
|
}
|
||||||
|
FastLED.show();
|
||||||
|
hue++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void rainbowLoop(){
|
||||||
|
long millisIn = millis();
|
||||||
|
long loopTime = 5000; // 5 seconds
|
||||||
|
|
||||||
|
while(millis() < millisIn + loopTime){
|
||||||
|
rainbow();
|
||||||
|
delay(5);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue