#include <FastLED.h>
#include <IRremote.h>
#define NUM_LEDS 60
#define LED_PIN 5
#define BRIGHTNESS 255
#define CHIPSET WS2811
#define COLOR_ORDER GRB
#define TEMPERATURE_1 Candle
CRGB leds[NUM_LEDS];
const byte receive_pin = 8;
uint8_t loop_run = 0;
unsigned long previousMillis = 0;
const long interval = 1000;
uint8_t ir_signal = 0;
CRGBPalette16 currentPalette;
CRGBPalette16 targetPalette;
TBlendType currentBlending;
void setup() {
delay(3000); // power-up safety delay
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalSMD5050);
FastLED.setBrightness(BRIGHTNESS);
FastLED.setTemperature(TEMPERATURE_1); // Set color-temperature
currentPalette = RainbowColors_p;
currentBlending = LINEARBLEND;
Serial.begin(9600);
IrReceiver.begin(receive_pin);
}
void loop() {
if (IrReceiver.decode() ) {
IrReceiver.printIRResultShort(&Serial);
if((IrReceiver.decodedIRData.command) == 0x40) { FastLED.setBrightness(200); }
else if((IrReceiver.decodedIRData.command) == 0x19) { FastLED.setBrightness(160); }
else if((IrReceiver.decodedIRData.command) == 0xA8) { loop_run = 1; }
else if((IrReceiver.decodedIRData.command) == 0x68) { currentPalette = RainbowColors_p; currentBlending = LINEARBLEND; }
else if((IrReceiver.decodedIRData.command) == 0x30) { SetupMyPalette_01(); currentBlending = LINEARBLEND; }
else if((IrReceiver.decodedIRData.command) == 0x18) { SetupMyPalette_02(); currentBlending = LINEARBLEND; }
static uint8_t startIndex = 0;
startIndex += 0; /* motion speed */
FillLEDsFromPaletteColors( startIndex);
IrReceiver.resume();
FastLED.show();
uint8_t ir_signal = 1;
}
//if (loop_run == 1) { ChangePalettePeriodically(); FastLED.show(); Serial.println(loop_run);
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
// function2
}
uint8_t maxChanges = 5;
nblendPaletteTowardPalette (currentPalette, targetPalette, maxChanges);
static uint8_t startIndex = 0;
startIndex += 0; /* motion speed */
FillLEDsFromPaletteColors( startIndex);
if (ir_signal == 1) {
for (uint16_t i=1; i=1000; i++) {
}
FastLED.show();
ir_signal = 0;
}
}
void ChangePalettePeriodically()
{
uint8_t secondHand = (millis() / 1000) % 15;
static uint8_t lastSecond = 99;
if( lastSecond != secondHand) {
lastSecond = secondHand;
if( secondHand == 0) { targetPalette = RainbowColors_p; currentBlending = LINEARBLEND; }
if( secondHand == 5) { targetPalette = ForestColors_p; currentBlending = LINEARBLEND; }
if( secondHand == 10) { targetPalette = PartyColors_p; currentBlending = LINEARBLEND; }
}
}
void FillLEDsFromPaletteColors( uint8_t colorIndex)
{
for( uint8_t i = 0; i < NUM_LEDS; i++) {
leds[i] = ColorFromPalette( currentPalette, colorIndex, BRIGHTNESS, currentBlending);
//colorIndex += 3;
colorIndex = colorIndex + (256/NUM_LEDS);
}
}
void SetupMyPalette_01()
{
CRGB col1 = CRGB(255, 200, 0);
CRGB col2 = CRGB(230, 0, 255);
CRGB col3 = CRGB::Red;
targetPalette = CRGBPalette16(col1, col1, col1, col1, col1, col2, col2, col2,
col2, col2, col2, col3, col3, col3, col3, col3 );
}
void SetupMyPalette_02()
{
CRGB col1 = CRGB( 255, 0, 0);
CRGB col2 = CRGB( 0, 255, 0);
CRGB col3 = CRGB( 0, 0, 255);
targetPalette = CRGBPalette16(col1, col1, col1, col1, col1, col2, col2, col2,
col2, col2, col2, col3, col3, col3, col3, col3 );
}