I'm trying to write some code to control a WS2812B LED strip using an IR remote using the FastLED library. I'm able to control the fill_solid and BRIGHTNESS cases properly, but I'm having trouble with the 0xFFA25D ("CH-") case. I want it to be able to run continuously until another button is pressed, but I can't seem to get the IR receiver to read within the while loop.
#include <IRremote.h>
#include <FastLED.h>
#define LED_PIN 8
#define NUM_LEDS 55
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
int BRIGHTNESS = 55;
const int RECV_PIN = 7;
IRrecv irrecv(RECV_PIN);
decode_results results;
unsigned long key_value = 0;
CRGBPalette16 effects[4];
int count = 0;
int hold = 1;
void setup() {
Serial.begin(9600);
irrecv.enableIRIn();
irrecv.blink13(true);
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness(BRIGHTNESS);
effects[0] = RainbowColors_p;
effects[1] = RainbowStripeColors_p;
effects[2] = CloudColors_p;
effects[3] = PartyColors_p;
}
void loop() {
if (irrecv.decode(&results)) {
if (results.value == 0XFFFFFFFF)
results.value = key_value;
switch (results.value) {
case 0xFFA25D:
Serial.println("CH-");
hold = 1;
while (hold == 1) {
static uint8_t startIndex = 0;
startIndex = startIndex + 1; /* motion speed */
FillLEDsFromPaletteColors(startIndex);
FastLED.show();
FastLED.delay(10);
irrecv.resume();
if (results.value != 0xFFA25D) {
hold = 0;
}
}
break;
case 0xFF629D:
Serial.println("CH");
break;
case 0xFFE21D:
Serial.println("CH+");
break;
case 0xFF22DD:
Serial.println("|<<");
break;
case 0xFF02FD:
Serial.println(">>|");
count++;
break ;
case 0xFFC23D:
Serial.println(">|");
break ;
case 0xFFE01F:
Serial.println("-");
BRIGHTNESS -= 10;
if (BRIGHTNESS < 0) {
BRIGHTNESS = 0;
}
FastLED.setBrightness(BRIGHTNESS);
FastLED.show();
break ;
case 0xFFA857:
Serial.println("+");
BRIGHTNESS += 10;
if (BRIGHTNESS > 255) {
BRIGHTNESS = 255;
}
FastLED.setBrightness(BRIGHTNESS);
FastLED.show();
break ;
case 0xFF906F:
Serial.println("EQ");
break ;
case 0xFF6897:
Serial.println("0");
fill_solid(leds, NUM_LEDS, CRGB::Black);
FastLED.show();
break ;
case 0xFF9867:
Serial.println("100+");
break ;
case 0xFFB04F:
Serial.println("200+");
break ;
case 0xFF30CF:
Serial.println("1");
fill_solid(leds, NUM_LEDS, CRGB::Red);
FastLED.show();
break ;
case 0xFF18E7:
Serial.println("2");
fill_solid(leds, NUM_LEDS, CRGB::Green);
FastLED.show();
break ;
case 0xFF7A85:
Serial.println("3");
fill_solid(leds, NUM_LEDS, CRGB::Blue);
FastLED.show();
break ;
case 0xFF10EF:
Serial.println("4");
fill_solid(leds, NUM_LEDS, CRGB::Magenta);
FastLED.show();
break ;
case 0xFF38C7:
Serial.println("5");
fill_solid(leds, NUM_LEDS, CRGB::Cyan);
FastLED.show();
break ;
case 0xFF5AA5:
Serial.println("6");
fill_solid(leds, NUM_LEDS, CRGB::Yellow);
FastLED.show();
break ;
case 0xFF42BD:
Serial.println("7");
fill_solid(leds, NUM_LEDS, CRGB::Pink);
FastLED.show();
break ;
case 0xFF4AB5:
Serial.println("8");
fill_solid(leds, NUM_LEDS, CRGB::Orange);
FastLED.show();
break ;
case 0xFF52AD:
Serial.println("9");
fill_solid(leds, NUM_LEDS, CRGB::White);
FastLED.show();
break ;
}
key_value = results.value;
irrecv.resume();
}
}
void FillLEDsFromPaletteColors(uint8_t colorIndex)
{
for ( int i = 0; i < NUM_LEDS; i++) {
leds[i] = ColorFromPalette(effects[0], colorIndex, BRIGHTNESS, LINEARBLEND);
colorIndex += 3;
}
}
Thank you for any help!
User contributions licensed under CC BY-SA 3.0