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