
#include <IRremote.h>
int bright;
int before;
int out = 8;
int steps = 8;
int RECV_PIN = 9; //signal of IR receiver connects to pin 9

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup() {
  irrecv.enableIRIn();
  before = 0;
  bright = 255;
  pinMode(out, OUTPUT);
}

void loop()
{
if (irrecv.decode(&results))
{
if (results.value == 0xaaaaaaa)
{
if (before == 0)
{
 digitalWrite(out, HIGH);
 before = 1;
}
else {
digitalWrite(out, LOW);
before = 0;
bright = 255;
}
}
if (results.value == 0xaaaaaaaa && before == 1) 
{
if (bright - 255 / steps < 0) {
analogWrite(out, bright);
}
else {
bright = bright - 255 / steps;
analogWrite(out, bright);
}
}
if (results.value == 0xaaaaaaaaa && before == 1) {
if (bright + 255 / steps > 255) {
analogWrite(out, bright);
}
else {
bright = bright + 255 / steps;
analogWrite(out, bright);
}
}

    irrecv.resume();
  }
}




