Hello again,
I am trying to utilize IR and LCD with Arduino (NANO) and The code is working just fine except for the led flashing part of the code
I want flashing LEDs to stop once I hit the OFF button or once I hit any other LED color so that that specific color would turn on and flashing will stop. I tried a lot but I couldnt find out how to do It. Help is appreciated
Here is the code
#include <Arduino.h>
#include <IRremote.h>
#include <LiquidCrystal.h>
int RECV_PIN = 10; // Define RECV_PIN as pin #10 "Must be PWM enabled"
IRrecv irrecv(RECV_PIN); // Declare the IR recieve pin "Must be PWM enabled"
decode_results results; // create an object called results , from the decode_results class, which will be used by the irrecv object to share the decoded information with our application
#define BUTTON_on 0xF7C03F
#define BUTTON_off 0xF740BF
#define BUTTON_red 0xF720DF
#define BUTTON_green 0xF7A05F
#define BUTTON_blue 0xF7609F
#define BUTTON_white 0xF7E01F
#define BUTTON_bup 0xF700FF
#define BUTTON_bdown 0xF7807F
#define BUTTON_flash 0xF7D02F
LiquidCrystal LCD (2, 3, 4, 5, 6, 7); //Set a LCD object and select it's pins (Rs,E,D4,D5,D6,D7)
int blue_LED = 11;
int red_LED = 12;
int green_LED = 13;
int flashdelay = 50;
void ledFlasher();
int flag=0;
void setup() {
pinMode(blue_LED, OUTPUT);
pinMode(red_LED, OUTPUT);
pinMode(green_LED, OUTPUT);
irrecv.enableIRIn(); //start the IR receiver by calling the IRrecv member function enableIRIn()
LCD.begin(16, 2); // Start the predefined object, which is the 'LCD' which represents the Liquid crystal display which is connected to the pins specified before the printhesis represents the (# of columns,# of rows)
LCD.setCursor(0, 0); //tells LCD where to start printing. because columns and rows start from ZERO then, (0,0) represents the column 0 row 0 which is the top left cornef of the LCD so this will set LCD cursor to top left corner
LCD.print("The LED game ;)"); //Print this line on the LCD
} // End of void setup
void loop() {
if (irrecv.decode(&results)) // Start of 'if-1' loop
{
if (results.value == BUTTON_off)
{
digitalWrite(blue_LED, LOW);
digitalWrite(red_LED, LOW);
digitalWrite(green_LED, LOW);
LCD.setCursor(0, 1);
LCD.print(" ");
LCD.setCursor(0, 1);
LCD.print("LEDs are OFF :(");
}
if (results.value == BUTTON_on)
{
LCD.setCursor(0, 1);
LCD.print(" ");
LCD.setCursor(0, 1);
LCD.print("All LEDs are :)");
digitalWrite(blue_LED, HIGH);
digitalWrite(red_LED, HIGH);
digitalWrite(green_LED, HIGH);
}
if (results.value == BUTTON_blue)
{
LCD.setCursor(0, 1);
LCD.print(" ");
LCD.setCursor(0, 1);
LCD.print("Blue LED is ON");
digitalWrite(blue_LED, HIGH);
}
if (results.value == BUTTON_red)
{
LCD.setCursor(0, 1);
LCD.print(" ");
LCD.setCursor(0, 1);
LCD.print("Red LED is ON");
digitalWrite(red_LED, HIGH);
}
if (results.value == BUTTON_green)
{
LCD.setCursor(0, 1);
LCD.print(" ");
LCD.setCursor(0, 1);
LCD.print("Green LED is ON");
digitalWrite(green_LED, HIGH);
}
if (results.value == BUTTON_flash) { // Flasher 'if' loop
while (results.value == BUTTON_flash)
{
LCD.setCursor(0, 1);
LCD.print(" ");
LCD.setCursor(0, 1);
LCD.print("Flash em' up man!");
digitalWrite(blue_LED, LOW);
digitalWrite(blue_LED, LOW);
digitalWrite(blue_LED, LOW);
digitalWrite(blue_LED, HIGH);
delay(flashdelay);
digitalWrite(blue_LED, LOW);
digitalWrite(red_LED, HIGH);
delay(flashdelay);
digitalWrite(red_LED, LOW);
digitalWrite(green_LED, HIGH);
delay(flashdelay);
digitalWrite(green_LED, LOW);
delay(flashdelay);
irrecv.resume();
if (irrecv.decode(&results)) {
if (results.value == BUTTON_off){
digitalWrite(red_LED, LOW);
digitalWrite(blue_LED, LOW);
digitalWrite(green_LED, LOW);
}
}
} // End of while loop
} // End of Flasher 'if' loop
irrecv.resume(); // Resume recieving IR radiations and data
} // End of 'if-1' loop
} // End of void loop