Im trying to have another button on the ir remote be an off for the relays and need some help with programing that. id like to use the button on the remote that correlates to the hex code 0xFF38C7
current code without off button
l
l
V
#include <IRremote.h>
//IR stuff
const int receiver = 13;
IRrecv irrecv(receiver);
decode_results results;
#define Button_1 0xFF18E7
#define Button_2 0xFF4AB5
#define LIGHT_ON LOW
#define LIGHT_OFF HIGH
//define the pins on the Arduino controlling the relays
const byte pinRed = 2;
const byte pinYel = 3;
const byte pinGrn = 4;
//what the switch will do
#define FLASHING_SEQUENCE HIGH
#define STATIC_ON LOW
const byte pinSelSwitch = 5; //select between flashing and static-on states
//an array of the light pin numbers that makes it
//easy to access them
byte grTrafficLights[] =
{
pinRed,
pinYel,
pinGrn
};
//you may need to swap these depending on how you're driving
//the light relays
#define LIGHT_ON LOW
#define LIGHT_OFF HIGH
//a holder for the millis() count when timing the lights
unsigned long
timeTrafficLight;
//keeps track of which light is on
//0=red, 1=yellow, 2=green
//after green is done, the count is set back to 0 (red)
byte
activeLight = 0;
byte
lastSwitch;
bool
bSelect; //if true, lights flash; if false, they're on static
void setup()
{
irrecv.enableIRIn(); //start the receiver
//set up the pins and set the RED light on
pinMode( pinRed, OUTPUT );
pinMode( pinYel, OUTPUT );
pinMode( pinGrn, OUTPUT );
InitLamps();
pinMode( pinSelSwitch, INPUT_PULLUP );
lastSwitch = digitalRead( pinSelSwitch );
//enable the flashing out of reset
bSelect = true;
}//setup
void loop()
{
byte
bChangeFlag;
byte
currSw;
bChangeFlag = 0;
if ( irrecv.decode(&results) )
{
irrecv.resume();
//if we have received an IR signal
//is it button 1?
if ( results.value == Button_1 )
bChangeFlag = 0x01;
else if ( results.value == Button_2 )
bChangeFlag = 0x02;
}//if
currSw = digitalRead( pinSelSwitch );
if ( currSw != lastSwitch )
{
lastSwitch == currSw;
bChangeFlag = 0x03;
}//if
if ( bChangeFlag == 0x01 || ((bChangeFlag == 0x03) && (currSw == STATIC_ON)) )
{
//IR button 1
LampsOn();
bSelect = false;
}//if
else if ( bChangeFlag == 0x02 || ((bChangeFlag == 0x03) && (currSw == FLASHING_SEQUENCE)) )
{
//IR button 2
//FLASHING_SEQUENCE
InitLamps();
bSelect = true;
}//if
//if flashing is enabled, do it
if ( bSelect )
DoTrafficLights();
}//loop
void InitLamps( void )
{
//init lights and timer for sequenced blinking
digitalWrite( pinRed, LIGHT_ON );
digitalWrite( pinYel, LIGHT_OFF );
digitalWrite( pinGrn, LIGHT_OFF );
timeTrafficLight = millis();
}//InitLamps
void LampsOn( void )
{
//turn all the lights on
digitalWrite( pinRed, LIGHT_ON );
digitalWrite( pinYel, LIGHT_ON );
digitalWrite( pinGrn, LIGHT_ON );
}//LampsOn
void DoTrafficLights( void )
{
//has 2.5-seconds (2500mS) passed?
if ( millis() - timeTrafficLight > 2500 )
{
//yes turn off the current light
digitalWrite( grTrafficLights[activeLight], LIGHT_OFF );
//bump the active light counter. If it goes over
//2 (green) set it back to 0 (red)
activeLight++;
if ( activeLight == 3 )
activeLight = 0;
//now turn on that light
digitalWrite( grTrafficLights[activeLight], LIGHT_ON );
//save this time for the next 2.5-sec period
timeTrafficLight = millis();
}//if
}//loop