ir remote and flashing leds

Hello all,
i'm new to Arduino and C code as a whole and i seem to be having trouble with my first big project.
So basically what i'm trying to achieve is 4 outputs (LEDS) being controlled by a IR remote but the twist is i need 2 of the outputs to start flashing when a button on the remote is pressed and keep flashing until another button on the remote is pressed.
To set a LED to high i have to write the code like this

 case 2079:  //IR remote button code
      digitalWrite(landing, 1);
      Serial.println("LANDING/TAXI/LOGO LIGHTS ENGAGED");
      break;

that's all fine and dandy and works a treat but only for setting something high or low manualy, i cant figure out how to make it flash every once in a while when a button on the remote is pressed and stop when another is pressed.

i tried using the milis() function as shown here

 case 2060:  //IR remote button code
      {
      Serial.println("STROBE ACTIVATED");
      unsigned long currentMillis = millis();
      if(currentMillis - prevMillis > interval) {
       prevMillis = currentMillis;
       if (strobeState == 0)
       strobeState = 1;
       else
       strobeState = 0;
       digitalWrite(strobe, strobeState);
      }
    }
      break;

All this seemed to do was turn the LED on and off as if i did a digitalWrite(strobe, 1)
Also i forgot to mention each output has to do its own thing - as if they each had their own void loop()

here's the rest of the code

#include <IRremote.h>

int irPin = 11; //ir sensor pin
int landing = 5; //landing lights, taxi lights and logo lights
int Position = 6; //red/green/white lights on wing tips - no flash -
int antiCol = 7; //red flashing lights on top and bottom
const int strobe = 8; //tail and wingtips
int all[] = {5, 6, 7, 8}; //all lights
int strobeState = LOW;
long prevMillis = 0;
long interval = 3500; //time between flashes

IRrecv irrecv(irPin);
decode_results results;

void setup(){
  Serial.begin(9600); //starts serial monitor *for debuging*
  irrecv.enableIRIn(); //starts IR reciever
  pinMode(landing, OUTPUT);
  pinMode(Position, OUTPUT);
  pinMode(antiCol, OUTPUT);
  pinMode(strobe, OUTPUT);
}

void loop(){
  if (irrecv.decode(&results)){
    long int decCode = results.value;
    Serial.println(decCode);
    switch (results.value){
      case 2079:
      digitalWrite(landing, 1);
      Serial.println("LANDING/TAXI/LOGO LIGHTS ENGAGED");
      break;
      
      case 31:
      digitalWrite(landing, 0);
      Serial.println("LANDING/TAXI/LOGO LIGHTS DISENGAGED");
      break;
      
      case 2108:
      digitalWrite(Position, 1);
      Serial.println("POSITION LIGHTS ENGAGED");
      break;
      
      case 60:
      digitalWrite(Position, 0);
      Serial.println("POSITION LIGHTS DISENGAGED");
      break;
      
      case 2060:
      {
      Serial.println("STROBE ACTIVATED");
      unsigned long currentMillis = millis();
      if(currentMillis - prevMillis > interval) {
       prevMillis = currentMillis;
       if (strobeState == 0)
       strobeState = 1;
       else
       strobeState = 0;
       digitalWrite(strobe, strobeState);
      }
    }
      break;
      
      default:
      Serial.println("WAITING");
    }
    irrecv.resume();
  }
}

so can anyone help me with this i've tried searching all over the place with no luck so now i'm asking you guys
Many thanks in advance :slight_smile:

You only change the state of your strobe when you receive a 2060 command from the remote, so it isn't going to flash. Move the flashing millis code out of the code controlled by this if:

  if (irrecv.decode(&results)){

i.e. move it to the very bottom of loop.

Add a boolean variable that tells you whether the strobe is supposed to be flashing. Toggle it when you receive a 2060. If the strobe should flash, run the millis code that does so.

wildbill:
Add a boolean variable that tells you whether the strobe is supposed to be flashing. Toggle it when you receive a 2060. If the strobe should flash, run the millis code that does so.

As i said i am really new to C code, how would i implement a boolean variable to this code? I've done some research but haven't found anything that really explains how i can use it.
Thanks for the reply by the way :slight_smile:

#include <IRremote.h>

int irPin = 11; //ir sensor pin
int landing = 5; //landing lights, taxi lights and logo lights
int Position = 6; //red/green/white lights on wing tips - no flash -
int antiCol = 7; //red flashing lights on top and bottom
const int strobe = 8; //tail and wingtips
int all[] = {5, 6, 7, 8}; //all lights
int strobeState = LOW;
long prevMillis = 0;
long interval = 3500; //time between flashes
bool StrobeIsFlashing=false;

IRrecv irrecv(irPin);
decode_results results;

void setup(){
  Serial.begin(9600); //starts serial monitor *for debuging*
  irrecv.enableIRIn(); //starts IR reciever
  pinMode(landing, OUTPUT);
  pinMode(Position, OUTPUT);
  pinMode(antiCol, OUTPUT);
  pinMode(strobe, OUTPUT);
}

void loop(){
  if (irrecv.decode(&results)){
    long int decCode = results.value;
    Serial.println(decCode);
    switch (results.value){
      case 2079:
      digitalWrite(landing, 1);
      Serial.println("LANDING/TAXI/LOGO LIGHTS ENGAGED");
      break;
      
      case 31:
      digitalWrite(landing, 0);
      Serial.println("LANDING/TAXI/LOGO LIGHTS DISENGAGED");
      break;
      
      case 2108:
      digitalWrite(Position, 1);
      Serial.println("POSITION LIGHTS ENGAGED");
      break;
      
      case 60:
      digitalWrite(Position, 0);
      Serial.println("POSITION LIGHTS DISENGAGED");
      break;
      
      case 2060:
      Serial.println("STROBE ACTIVATED");
      StrobeIsFlashing=!StrobeIsFlashing;    
      break;
      
      default:
      Serial.println("WAITING");
    }
    irrecv.resume();
  }
if(StrobeIsFlashing)
  {
  FlashStrobe();  
  }
}

void FlashStrobe()
{
unsigned long currentMillis = millis();
if(currentMillis - prevMillis > interval) 
  {
  prevMillis = currentMillis;
  if (strobeState == 0)
    strobeState = 1;
  else
    strobeState = 0;
  digitalWrite(strobe, strobeState);
  }
}

Not tested. Compiles with errors because I don't have the IR lib.

Thankyou very much for this, ill test it tomorrow after school :slight_smile: