Hello all. First time poster here on the forms. I'm working on an LED lighting project and I'm trying to incorporate an IR sensor so that I can control the LED's. What I don't get is that when I have code in my project that updates my lighting, the IR sensor gets random codes. When I only have the IR code, it receives the right codes no problem. I have a feeling this is a timing issue and I'm trying to figure out how to reliably get correct codes so that I can eventually change patterns, colors, etc. on my led strip. Below is the serial output when it's not working correctly.
other button
54970BD9
other button
3DFE8207
other button
BBC3DDA
other button
4325BA15
other button
8A0F61A8
other button
A1E3DE0C
other button
CEF52AD2
And blow is my code.
#include <FastLED.h>
#include <IRremote.h>
//Strip Light Objects
#define NUM_LEDS 240 // How many LEDs we're lighting
CRGB leds[NUM_LEDS]; // Declare Strip Array
#define PIN 6 // Pin that controls strip
byte hue; // Use to hold colors
//IR Remote Objects
int receiver = 3; // Pin that listens for IR
IRrecv irrecv(receiver); // Declare IR Object
decode_results results; // Holds IR Result Codes
/* IR Receive Codes
0xFFA25D: POWER
0xFFE21D: FUNC/STOP
0xFF629D: VOL+
0xFF22DD: FAST BACK"
0xFF02FD: PAUSE
0xFFC23D: FAST FORWARD
0xFFE01F: DOWN
0xFFA857: VOL-
0xFF906F: UP
0xFF9867: EQ
0xFFB04F: ST/REPT
0xFF6897: 0
0xFF30CF: 1
0xFF18E7: 2
0xFF7A85: 3
0xFF10EF: 4
0xFF38C7: 5
0xFF5AA5: 6
0xFF42BD: 7
0xFF4AB5: 8
0xFF52AD: 9
0xFFFFFFFF: Repeat
*/
void setup()
{
//Setup LED Strip
FastLED.addLeds<NEOPIXEL, PIN>(leds, NUM_LEDS);
FastLED.setBrightness(255);
FastLED.clear();
//Setup IR Receiver
irrecv.enableIRIn();
Serial.begin(9600);
}
void loop() {
if (irrecv.decode(&results)) {
switch(results.value) {
case 0xFFA25D: Serial.println("POWER"); break;
case 0xFFE21D: Serial.println("FUNC/STOP"); break;
case 0xFF629D: Serial.println("VOL+"); break;
case 0xFFFFFFFF: Serial.println(results.value, HEX);break;
default: Serial.println(" other button ");
}
irrecv.resume();
delay(500);
Serial.println(results.value, HEX);
}
if (random(2)) {
hue = 0;
} else {
hue = 160;
}
if( random8() < 200) {
leds[random16(NUM_LEDS)] = CHSV(hue, 255, 255);
}
fadeToBlackBy(leds, NUM_LEDS, 10);
FastLED.show();
delay(20);
}
Any insight is greatly appreciated.
