Hello! I am trying to Use an IR remote and sensor to control the function of an LED. I can get the LED to blink, or turn on or off with the IR remote, but I can't seem to get it to gradually get brighter and dimmer (AKA "pulse"). I have been able to get it to pulse when I send inputs from my keyboard, but for some reason it won't do it when getting an input from my IR remote. Instead, when my arduino receives the input from my remote to pulse the LED, the LED only flashes on briefly and then turns off, instead of gradually getting brighter and dimmer. Here is the code I am using...
#include "IRremote.h"
int receiver = 7; //reciever signal pin
int ledPin = 3;
IRrecv irrecv(receiver);
decode_results results;
void translateIR() {
switch(results.value)
{
case 0xFFA25D: Serial.println("POWER");
for(int i = 0; i < 255; i++) {
analogWrite(ledPin, i);
delay(10);
}
for(int j = 255; j >= 0; j--) {
analogWrite(ledPin, j);
delay(10);
}
digitalWrite(ledPin, HIGH);
break;
default :
Serial.println(" other button : ");
Serial.println(results.value);
}
delay(500);
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("IR Receiver Button Decode");
irrecv.enableIRIn();
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
}
void loop() {
// put your main code here, to run repeatedly:
if(irrecv.decode(&results)) //have we received an IR signal?
{
translateIR();
irrecv.resume(); //receive next value
}
}
The 'for' loops used to pulse the LED works without the IR remote, just not when prompted by the remote, so I know the problem isn't the 'for' loops, it has to be something with how the code works with the IR remote. Any ideas?
THANKS!