I'm trying to control a series of LEDs using an IR remote. I have a problem when I try to play a sequence with the LEDs where they all light up in a line and turn off accordingly. I loop through the sequence and I am trying to make it so the instant I press a button on the remote it breaks out of that sequence. The issue lies in the Flash(); function, I think. What can I do?
#include <boarddefs.h>
#include <IRremote.h>
#include <IRremoteInt.h>
#include <ir_Lego_PF_BitStreamEncoder.h>
int recvPin = 11;
IRrecv irrecv(recvPin);
decode_results results;
#define BUTTON_ON 0xF076C13B // codes for different buttons on the remote
#define BUTTON_OFF 0xFF9186B7
#define BUTTON_R 0xE5CFBD7F
#define BUTTON_G 0x8C22657B
#define BUTTON_B 0x2A89195F
#define BUTTON_FLASH 0x35A9425F
int rLED = 5;
int gLED = 4;
int bLED = 3;
int stR = LOW; // intital state of red LED
int stG = LOW; // intital state of green LED
int stB = LOW; // initial state of blue LED
int flash = false;
void setup() {
Serial.begin(9600); // Status message will be sent to PC at 9600 baud
pinMode(rLED, OUTPUT);
pinMode(gLED, OUTPUT);
pinMode(bLED, OUTPUT);
irrecv.enableIRIn();
}
void Flash() { // flashing function
while (flash == false) {
digitalWrite(rLED, LOW);
digitalWrite(gLED, LOW);
digitalWrite(bLED, LOW);
digitalWrite(rLED, HIGH);
delay(75);
digitalWrite(gLED, HIGH);
delay(75);
digitalWrite(bLED, HIGH);
delay(75);
digitalWrite(rLED, LOW);
delay(75);
digitalWrite(gLED, LOW);
delay(75);
digitalWrite(bLED, LOW);
delay(75);
stR = LOW;
stG = LOW;
stB = LOW;
if (results.value == BUTTON_OFF) // attempting to make it so when i press the OFF button on the remote,
{ // the loop breaks/stops and I can go back to pressing any button on
break; // the remote
}
}
}
void loop() {
if (irrecv.decode(&results))
{
if (results.value == BUTTON_ON)
{
digitalWrite(rLED, HIGH);
digitalWrite(gLED, HIGH);
digitalWrite(bLED, HIGH);
stR = HIGH;
stG = HIGH;
stB = HIGH;
}
if (results.value == BUTTON_OFF)
{
digitalWrite(rLED, LOW);
digitalWrite(gLED, LOW);
digitalWrite(bLED, LOW);
stR = LOW;
stG = LOW;
stB = LOW;
}
if (results.value == BUTTON_R)
{
digitalWrite(rLED, !stR);
stR = !stR;
}
if (results.value == BUTTON_G)
{
digitalWrite(gLED, !stG);
stG = !stG;
}
if (results.value == BUTTON_B)
{
digitalWrite(bLED, !stB);
stB = !stB;
}
if (results.value == BUTTON_FLASH)
{
Flash(); // calling flash func
}
irrecv.resume();
}
}