#include int RECV_PIN = 2; // IR receiver pin const unsigned long KEYUPCODE = 0x20DFE21D; const unsigned long KEYOKCODE = 0x20DFD22D; const unsigned long KEYDOWNCODE = 0x20DF12ED; IRrecv irrecv(RECV_PIN); decode_results results; int loga[64]= { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 18, 20, 22, 25, 28, 30, 33, 36, 39, 42, 46, 49, 53, 56, 60, 64, 68, 72, 77, 81, 86, 90, 95, 100, 105, 110, 116, 121, 127, 132, 138, 144, 150, 156, 163, 169, 176, 182, 189, 196, 203, 210, 218, 225, 233, 240, 248, 255 }; int ledPin1 = 6; // PWM output pin 1 int tmax = 60; // max random delay int tmin = 15; // min delay int light = 40; // start lightness of LED int step; // random lightness step void setup() { Serial.begin(9600); // Serial port to debugging irrecv.enableIRIn(); // Start the receiver randomSeed(0); // Stard random generator } int i = 0; unsigned long last = millis(); void loop() { if (irrecv.decode(&results)) { // If it's been at least 1/4 second since the last // IR received, toggle the relay if (millis() - last > 250) { switch (results.value){ case KEYUPCODE: // key UP pressed step=random(-5,5); // -5... +5 light = light+step; if(light>=64) light=61; // max light = 64 if(light<=9) light=12; // min light = 10 analogWrite (ledPin1, loga[light]); delay (random(tmax)+tmin); break; case KEYOKCODE: // key OK pressed (STOP) analogWrite (ledPin1, 0); break; case KEYDOWNCODE: // key DOWN pressed analogWrite (ledPin1, 0); break; } } last = millis(); if (irrecv.decode(&results)) { Serial.println(results.value, HEX); // debug to serial monitor irrecv.resume(); // Receive the next value } } }