arduino: remote control lamp
#include <IRremote.h>
#include <IRremoteInt.h>
const int receiver = 11; // pin 1 of IR receiver to Arduino digital pin 11
const int led1 = 3;
const int led2 = 4;
const int led3 = 5;
IRrecv irrecv(receiver); // create instance of 'irrecv'
decode_results results;
boolean lightState1 = false;
boolean lightState2 = false;
boolean lightState3 = false;
unsigned long last1 = millis();
unsigned long last2 = millis();
unsigned long last3 = millis();
void setup()
{
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
irrecv.enableIRIn();
}
void loop()
{
if (irrecv.decode(&results))
{
if (results.value == 0xFF30CF)
{
if (millis() - last1 > 300)
{
lightState1 =!lightState1;
digitalWrite(led1,lightState1);
last1 = millis();
}
}
if (results.value == 0xFF18E7)
{
if (millis() - last2 > 300)
{
lightState2 =!lightState2;
digitalWrite(led2,lightState2);
last2 = millis();
}
}
if (results.value == 0xFF7A85)
{
if (millis() - last3 > 300)
{
lightState3 =!lightState3;
digitalWrite(led3,lightState3);
last3 = millis();
}
}
irrecv.resume();
}
}
0 comments:
Post a Comment