for eg. this is a code for switching leds on off with ir remote
in this when i press Forward button led light up
when i press Reverse button led1 light up
and when any thing else is pressed all go off
it act as a on off switch
i have to press some thing to turn led off
but i want it to act as a push button when Reverse button is pressed it light up and as soon as i release the reverse button it should go off
i tried to use while statment but using that nothing happen
on youtube there are many who have made ir cars but they press one buton to move it and again some other button to stop it
#include <IRremote.h>
int IR_Recv = 3; //IR Receiver Pin 3
int led = 9;
int led1 = 10;
int led2 = 11;
int led3 = 12;
IRrecv irrecv(IR_Recv);
decode_results results;
void setup(){
Serial.begin(9600); //starts serial communication
irrecv.enableIRIn(); // Starts the receiver
pinMode(led, OUTPUT); // sets the digital pin as output
pinMode(led1, OUTPUT); // sets the digital pin as output
pinMode(led2, OUTPUT); // sets the digital pin as output
pinMode(led3, OUTPUT); // sets the digital pin as output
}
void loop(){
//decodes the infrared input
if (irrecv.decode(&results)){
long int decCode = results.value;
Serial.println(decCode);
//switch case to use the selected remote control button
switch (results.value){
case 16722135: //when you press the Forward button
digitalWrite(led,HIGH);
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
digitalWrite(led3,LOW);
break;
case 16754775: //when you press the Reverse button
digitalWrite(led1,HIGH);
digitalWrite(led2,LOW);
digitalWrite(led3,LOW);
digitalWrite(led,LOW);
break;
case 16730295: //when you press the Mute button
digitalWrite(led2,HIGH);
digitalWrite(led3,LOW);
digitalWrite(led1,LOW);
digitalWrite(led,LOW);
break;
case 16724175: //when you press the Power button
digitalWrite(led3,HIGH);
digitalWrite(led2,LOW);
digitalWrite(led1,LOW);
digitalWrite(led,LOW);
default:
{
digitalWrite(led,LOW);
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
digitalWrite(led3,LOW);
}
}
irrecv.resume(); // Receives the next value from the button you press
}
}