Professional Documents
Culture Documents
h>
#include <FastLED.h>
CRGBPalette16 currentPalette;
TBlendType currentBlending;
//ir stuff
void setup() {
delay( 3000 ); // power-up safety delay
//Control scheme
Serial.begin(9600);// Serial Output
irrecv.enableIRIn(); // Start the IR receiver
//FastLED stuff
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds,
NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness( brightness );
SetupBlackPalette();
onoff = false;
}
void loop()
{
//ChangePalettePeriodically();
//store last command for repetition in case button is held
if (command != 4294967295){//when button is held on remote, this value is
received. If so, repeat the previous command until release.
lastcommand = command;
}else{
command = lastcommand;
}
switch (command) { //here is where you use the commands received from the
remote (seen through serial monitor). Each code must be listed here for anything to
happen
case 33706159: //power button
if (onoff == false){
colourscheme=1;
colourschemecycle(colourscheme);
onoff = true;
delay(1000);
}else{
colourscheme=0;
colourschemecycle(colourscheme);
onoff = false;
}
break;
//colour schemes
case 33748999: //up arrow - change colour scheme
if (colourscheme < colourschemeqty && colourscheme > 0){
colourscheme += 1;
}else if (colourscheme == colourschemeqty){
colourscheme=1;
}
colourschemecycle(colourscheme);
break;
case 33716359: //down arrow - change colour scheme
if (colourscheme > 1){
colourscheme -= 1;
}else if (colourscheme == 1){
colourscheme = colourschemeqty;
}
colourschemecycle(colourscheme);
break;
//brightness controls
case 33700039: //brightness down
if (brightness > 25){
brightness = brightness - 20;
}
colourschemecycle(colourscheme);
break;
case 33728599: //brightness up
if (brightness < 254){
brightness = brightness + 20;
}
colourschemecycle(colourscheme);
break;
default:
//SetupBlackPalette();
break;
}
//FastLED.delay(1000 / UPDATES_PER_SECOND);
delay(250);//delay for effect to finish processing. reduce to make smoother, but
currently causes issues with remote response
}
void SetupBlackPalette()
{
fill_solid( currentPalette, 16, CRGB::Black);
}
void SetupN7Palette()
{
CRGB red = CRGB::Red;
CRGB white = CRGB::Gray;
currentPalette = CRGBPalette16{
white, white, red, red,
red, white, white, white,
white, white, red, red,
red, white, white, white
};
}
void SetupTotallyRandomPalette()
{
for( int i = 0; i < 16; i++) {
currentPalette[i] = CHSV( random8(), 255, random8());
}
}
currentPalette = CRGBPalette16(
green, green, black, black,
purple, purple, black, black,
green, green, black, black,
purple, purple, black, black );
}
void SetupRedWhiteBluePalette()
{
CRGB red = CRGB::Red;
CRGB white = CRGB::Gray;
CRGB blue = CRGB::Blue;
CRGB black = CRGB::Black;
currentPalette = CRGBPalette16(
red, white, blue, black,
red, white, blue, black,
red, white, blue, black,
red, white, blue, black );
}
CRGB::Red,
CRGB::Gray,
CRGB::Blue,
CRGB::Black,
CRGB::Red,
CRGB::Red,
CRGB::Gray,
CRGB::Gray,
CRGB::Blue,
CRGB::Blue,
CRGB::Black,
CRGB::Black
};
// Additionl notes on FastLED compact palettes:
//
// Normally, in computer graphics, the palette (or "color lookup table")
// has 256 entries, each containing a specific 24-bit RGB color. You can then
// index into the color palette using a simple 8-bit (one byte) value.
// A 256-entry color palette takes up 768 bytes of RAM, which on Arduino
// is quite possibly "too many" bytes.
//
// FastLED does offer traditional 256-element palettes, for setups that
// can afford the 768-byte cost in RAM.
//
// However, FastLED also offers a compact alternative. FastLED offers
// palettes that store 16 distinct entries, but can be accessed AS IF
// they actually have 256 entries; this is accomplished by interpolating
// between the 16 explicit entries to create fifteen intermediate palette
// entries between each pair.
//
// So for example, if you set the first two explicit entries of a compact
// palette to Green (0,255,0) and Blue (0,0,255), and then retrieved
// the first sixteen entries from the virtual palette (of 256), you'd get
// Green, followed by a smooth gradient from green-to-blue, and then Blue.