#include <IRremote.hpp>
#define IR_RECEIVE_PIN 2
#define LED_PIN 3
bool toggle_on;
int duty_cycle;
void setup(){
Serial.begin(9600);
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); //FEEDBACK uključuje ugrađenu LED L
pinMode(LED_PIN, OUTPUT);
toggle_on = false;
duty_cycle=127;
}
void loop(){
if (IrReceiver.decode()){
IrReceiver.printIRResultShort(&Serial);
Serial.println(IrReceiver.decodedIRData.command);
if(IrReceiver.decodedIRData.command==162) //on - off power button
{
if(toggle_on){ //ako je uključena, isključi je
digitalWrite(LED_PIN, LOW);
toggle_on=false;
}
else{ //ako je isključena, uključi je
analogWrite(LED_PIN,duty_cycle);
toggle_on=true;
}
}
if(IrReceiver.decodedIRData.command==2){ // +
duty_cycle=duty_cycle+50;
if(duty_cycle>255) duty_cycle=255;
analogWrite(LED_PIN,duty_cycle);
}
if(IrReceiver.decodedIRData.command==152){ // -
duty_cycle=duty_cycle-50;
if(duty_cycle<0) duty_cycle=0;
analogWrite(LED_PIN,duty_cycle);
}
IrReceiver.resume();
Serial.println(duty_cycle);
}
}