here is the code
#include <IRremote.h>
#define PIN_RECEIVER A0
int Lane1[] = {13,12,11}; // Lane 1 Red, Yellow and Green
int Lane2[] = {10,9,8};// Lane 2 Red, Yellow and Green
int Lane3[] = {7,6,5};// Lane 3 Red, Yellow and Green
int Lane4[] = {4,3,2};// Lane 4 Red, Yellow and Green
boolean task48aEnable;
boolean task24aEnable;
boolean task122aEnable;
boolean task16aEnable;
unsigned long int runTask48a;
IRrecv receiver(PIN_RECEIVER);
decode_results results;
void setup()
{
receiver.enableIRIn();
for (int i = 0; i < 3; i++)
{
pinMode(Lane1[i], OUTPUT);
pinMode(Lane2[i], OUTPUT);
pinMode(Lane3[i], OUTPUT);
pinMode(Lane4[i], OUTPUT);
}
}
void loop()
{
if (receiver.decode())
{
translateIR();
receiver.resume(); // Receive the next value
}
if( task48aEnable == true and millis() > runTask48a)
{
if(receiver.decodedIRData.command==48)
{
task48a();
}
}
if( task24aEnable == true and millis() > runTask48a)
{
if(receiver.decodedIRData.command==24)
{
task24a();
}
}
if( task122aEnable == true and millis() > runTask48a)
{
if(receiver.decodedIRData.command==122)
{
task122a();
}
}
if( task16aEnable == true and millis() > runTask48a)
{
if(receiver.decodedIRData.command==16)
{
task16a();
}
}
}
void task48a(){
digitalWrite(Lane1[1], LOW);
digitalWrite(Lane1[2], HIGH); //lane 1-Green
task48aEnable = false; // do not run this task again until enabled
}
void task24a(){
digitalWrite(Lane3[1], LOW);
digitalWrite(Lane3[2], HIGH); //lane 3-Green
task24aEnable = false;
//runTask24a = 0; // do not run this task again until enabled
}
void task122a(){
digitalWrite(Lane4[1], LOW);
digitalWrite(Lane4[2], HIGH); //lane 4-Green
task122aEnable = false; // do not run this task again until enabled
}
void task16a(){
digitalWrite(Lane2[1], LOW);
digitalWrite(Lane2[2], HIGH); //lane 2-Green
task16aEnable = false; // do not run this task again until enabled
}
void translateIR()
{
// Takes command based on IR code received
switch (receiver.decodedIRData.command) {
case 48:
//Keypad button "1"
//Lane 1 - Green
digitalWrite(Lane1[0], LOW);
digitalWrite(Lane1[2], LOW);
digitalWrite(Lane1[1], HIGH); //lane 1-Yellow
digitalWrite(Lane3[1], LOW);
digitalWrite(Lane3[2], LOW);
digitalWrite(Lane3[0], HIGH); //lane 3-Red
digitalWrite(Lane4[1], LOW);
digitalWrite(Lane4[2], LOW);
digitalWrite(Lane4[0], HIGH); //lane 4-Red
digitalWrite(Lane2[1], LOW);
digitalWrite(Lane2[2], LOW);
digitalWrite(Lane2[0], HIGH); //lane 2-red
task48aEnable = true; // this is a global boolean variable.
runTask48a = millis() + 3000; // this is a global unsigned long int
break;
case 24:
//Keypad button "2"
//Lane 3 - Green
digitalWrite(Lane4[1], LOW);
digitalWrite(Lane4[2], LOW);
digitalWrite(Lane4[0], HIGH); //lane 4-Red
digitalWrite(Lane2[1], LOW);
digitalWrite(Lane2[2], LOW);
digitalWrite(Lane2[0], HIGH); //lane 2-Red
digitalWrite(Lane1[2], LOW);
digitalWrite(Lane1[1], LOW);
digitalWrite(Lane1[0], HIGH); //lane 1-Red
digitalWrite(Lane3[0], LOW);
digitalWrite(Lane3[2], LOW);
digitalWrite(Lane3[1], HIGH); //lane 3-Yellow
task24aEnable = true;
runTask48a = millis() + 3000;
break;
case 122:
//Keypad button "3"
//Lane 4 - Green
digitalWrite(Lane4[2], LOW);
digitalWrite(Lane4[0], LOW);
digitalWrite(Lane4[1], HIGH); //lane 4-Yellow
digitalWrite(Lane2[1], LOW);
digitalWrite(Lane2[2], LOW);
digitalWrite(Lane2[0], HIGH); //lane 2-Red
digitalWrite(Lane1[2], LOW);
digitalWrite(Lane1[1], LOW);
digitalWrite(Lane1[0], HIGH); //lane 1-Red
digitalWrite(Lane3[1], LOW);
digitalWrite(Lane3[2], LOW);
digitalWrite(Lane3[0], HIGH); //lane 3-Red
task122aEnable = true;
runTask48a = millis() + 3000;
break;
case 16:
//Keypad button "4"
//Lane 2 - green
digitalWrite(Lane4[2], LOW);
digitalWrite(Lane4[1], LOW);
digitalWrite(Lane4[0], HIGH); //lane 4-Red
digitalWrite(Lane2[0], LOW);
digitalWrite(Lane2[2], LOW);
digitalWrite(Lane2[1], HIGH); //lane 2-Yellow
digitalWrite(Lane1[2], LOW);
digitalWrite(Lane1[1], LOW);
digitalWrite(Lane1[0], HIGH); //lane 1-Red
digitalWrite(Lane3[1], LOW);
digitalWrite(Lane3[2], LOW);
digitalWrite(Lane3[0], HIGH); //lane 3-Red
task16aEnable = true;
runTask48a = millis() + 3000;
break;
case 162:
//Power button
// All Lane goes OFF
digitalWrite(Lane1[0], LOW);
digitalWrite(Lane1[2], LOW);
digitalWrite(Lane1[1], LOW);
digitalWrite(Lane3[1], LOW);
digitalWrite(Lane3[2], LOW);
digitalWrite(Lane3[0], LOW);
digitalWrite(Lane4[1], LOW);
digitalWrite(Lane4[2], LOW);
digitalWrite(Lane4[0], LOW);
digitalWrite(Lane2[1], LOW);
digitalWrite(Lane2[2], LOW);
digitalWrite(Lane2[0], LOW);
break;
}
}