While / do vs If args

I'm working on a project to make certain light colors blink when it receives an IR signal. My current code blinks a set of Green LED's which are self Blinking and a set of Red Leds which are also self blinking. So when the receiver receives Signal A, then the lights flash Green for 60 seconds. When it receives signal B, if it's still flashing Green then it will continue to flash Green for another 60 seconds however if it's not flashing Green, then it flashes Red instead. I tried using an if statement
if (result == A ){
digitalWrite(Red_Pin, LOW); // if red if flashing turn it off
digitalWrite(Green_Pin, HIGH); // turn on Green Flashing LED's
delay(60000); //wait 60 seconds
}
else if (result == B && Green_Pin == HIGH){ // look at IR signal B and Green_Pin still high
digitalWrite(Green_Pin, HIGH); // keep flashing Green for 60 seconds
delay(60000);
}
else if (result == B){
digitalWrite(Red_Pin, HIGH); // Flash forever until it gets a green A signal.
}
but for some reason, this code simply loads the IR_Result and stores it so when the board receives B it just turns on the Red LED's even if the Green LED's are flashing. I believe the Arduino is processing the arg and the delay period and the Pin State all at once and seeing the Pin State as Low even if it's still HIGH. So I think perhaps a "While" statement would work but I don't know the proper syntax to create a while statement. Would it be "While(Green_Pin ==High && IR_Result ==B)? Any help would be appreciated. Thank You.

#include <IRremote.h>
IRsend irsend;
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
pinMode(12, OUTPUT); // Green LED
pinMode(13, OUTPUT); // Red LED
pinMode(10, OUTPUT); // Speech Chip Init (Speak)
}

void loop() {

if (irrecv.decode(&results)) {
Serial.print(F("result = 0x"));
Serial.println(results.value, HEX); // I do this only to see the incoming IR code
if (results.value == 0xFF02FD) {
Serial.println("Green Flashing");
digitalWrite(13, LOW);
digitalWrite(12, HIGH);
delay(60000);
digitalWrite(12,LOW);
delay(500);
}
else if (results.value == 0xFF9867 && 12 == HIGH) {
Serial.println("Continue Flashing");
digitalWrite(12, HIGH); //
}
else if(result == 0xFF9867){
digitalWrite(10, HIGH);
delay(500);
digitalWrite(10, LOW); //Toggle signal to turn on RSC164I Speech Chip
digitalWrite(13, HIGH); // Turn on Red Blinking LED
delay(500);
}
irrecv.resume(); // Receive the next value
}
}

Please post your code using code tags

type
** **[code]** **

past your code after that
type
** **[/code]** **

So it looks like

 #include <IRremote.h>
IRsend irsend;
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  pinMode(12, OUTPUT); // Green LED
  pinMode(13, OUTPUT); // Red LED
  pinMode(10, OUTPUT); // Speech Chip Init (Speak)
}

void loop() {

  if (irrecv.decode(&results)) {
    Serial.print(F("result = 0x"));
    Serial.println(results.value, HEX); // I do this only to see the incoming IR code
if (results.value == 0xFF02FD)  {
      Serial.println("Green Flashing");
      digitalWrite(13, LOW);
      digitalWrite(12, HIGH);
      delay(60000);
      digitalWrite(12,LOW);
      delay(500);
    }
    else  if (results.value == 0xFF9867 && 12 == HIGH)  {
      Serial.println("Continue Flashing");
      digitalWrite(12, HIGH); //
    }
  else if(result == 0xFF9867){
      digitalWrite(10, HIGH);
      delay(500);
      digitalWrite(10, LOW); //Toggle signal to turn on RSC164I Speech Chip
     digitalWrite(13, HIGH); // Turn on Red Blinking LED
     delay(500);
}
    irrecv.resume(); // Receive the next value
  }
}

Have a look at the BlinkWithoutDelay example that comes with the IDE how to get rid of delay (I'm aware that the LEDs are self-flashing but the idea stays the same). Currently delay(60000) will block all other code. So only after 60 seconds the code will check again for the remote code; you will never have a chance to just restart your timing.

And what is this supposed to do?

    else  if (results.value == 0xFF9867 && 12 == HIGH)  {

12 is a number (12), HIGH is a number (1); they will never be equal. I guess you want to read the output of pin 12. Read up on digitalRead

The program is completely oblivious to the world while delay() is running. You have told the computer to take a 60 second vacation with pay.

&& 12 == HIGH

You are testing the value of the number 12 not the state of pin 12

The demo Several Things at a Time is an extended example of BWoD.

...R

Thanks. I'm new at this so sorry if I posted directly to anyone. Not sure how I might have done that because I thought I was posting to the forum and not to any particular person or persons. So as I see now the number 12 doesn't represent the Pin unless stated as a constant?

const int Green_LEDPin 12;

Then down in the arg

if(result == 0xFF092 && Green_LEDPin == HIGH){

Is this correct?
Thanks.

I see what you mean.. I think this will work! or at least a variation of it.

if (irrecv.decode(&results)) {
    		Serial.print(F("result = 0x"));
   		Serial.println(results.value, HEX); // I do this only to see the incoming IR code
	if (results.value == 0xFF02FD)  {
      		Serial.println("Green Flashing");
      		digitalWrite(13, LOW);
      		digitalWrite(12, HIGH);
      		delay(60000);
      		digitalWrite(12,LOW);
      		delay(500);
    }
    else  if(results.value == 0xFF9867)  {
		if(LEDState == HIGH){
			pinMode(12, HIGH); // Green continues to Flash
		}
	else if (LEDState == LOW){
			pinMode(10, HIGH); // Else it flashes Red
	}
    }

You should use

if(result == 0xFF092 && digitalRead(Green_LEDPin)){

With "digitalRead(Green_LEDPin)" do I use another "if statement to look to see if the pin is high or go ahead and assume the digitalRead arg will only read it if the pin is high? I mean somewhere the arg must assume the pin state is high along with the reception of the HEX sequence being true. Does "digitalRead" only look to the pin state when it's high? I hope I'm presenting this question correctly. Thanks

RTFM https://www.arduino.cc/en/Reference/DigitalRead

With "digitalRead(Green_LEDPin)" do I use another "if statement to look to see if the pin is high or go ahead and assume the digitalRead arg will only read it if the pin is high?

if(result == 0xFF092 && digitalRead(Green_LEDPin)){

is a shorter form of

if(result == 0xFF092 && digitalRead(Green_LEDPin) == HIGH){

If the digitalRead() returns LOW then that is equivalent to false, whereas HIGH is equivalent to true

neuralmorph:
Thanks. I'm new at this so sorry if I posted directly to anyone. Not sure how I might have done that because I thought I was posting to the forum and not to any particular person or persons.
[/code]

You did post to the forum and not an individual person; maybe you got confused because some people have a message in their signature

neuralmorph:
So as I see now the number 12 doesn't represent the Pin unless stated as a constant?

const int Green_LEDPin 12;

It represents number of the pin, it does not represent the state of the pin. Hence you have to use digitalRead() to get the state of the pin.

So I hope I have this correct. I'm going to work with it and check it out. Thank You all for your help. I'm getting a better understanding of the language. I'm porting over from Propeller chip to Arudino and it's quite different. Here's my final code in case you want to see it. Let me know if I did anything wrong. Thanks again.

#include <IRremote.h>
IRsend irsend;
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
const int RedLED_Pin = 12;
const int GreenLED_Pin = 13;
const int Speaker_Pin = 10;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  pinMode(RedLED_Pin, OUTPUT);  // define pinModes as outputs
  pinMode(GreenLED_Pin, OUTPUT);
  pinMode(Speaker_Pin, OUTPUT);
}

void loop() {
  if (irrecv.decode(&results)) { // look for incoming IR signal
    Serial.print(F("result = 0x"));   // Set HEX Reference
    Serial.println(results.value, HEX); //Print the value in HEX
if (results.value == 0xFF02FD)  {  //If Hex code = value, do arg
      Serial.println("Green On");
      digitalWrite(RedLED_Pin, LOW);  // turn off Red Blinking LED
      digitalWrite(GreenLED_Pin, HIGH); // Turn on Green Blinking LED
      delay(60000);                    // Wait 60 Seconds for new instructions
      digitalWrite(GreenLED_Pin,LOW); // Turn off Green Blinking LED
      delay(500);
    }
 else if(results.value == 0xFF9867 && digitalRead(GreenLED_Pin)){  // Read two values to be true else do other arg
      digitalWrite(GreenLED_Pin, HIGH);   // Turn on Green LED
      delay(30000);                      //Wait for New Command
      digitalWrite(GreenLED_Pin,LOW);   // Turn off Green LED
 }
     else if(results.value == 0xFF9867){    // Only one statement was true
      Serial.println("Red On");      // Print Serial to tell color LED
      digitalWrite(Speaker_Pin, HIGH);
      delay(500);                     // Toggle Speaker Pin
      digitalWrite(Speaker_Pin, LOW);
      digitalWrite(RedLED_Pin, HIGH);  // Flash Red LED and wait for Green Input
    }
    irrecv.resume(); // Receive the next value
  }
}