CIRCUIT
PROGRAM
//off -red — 33441975
//1 — 33444015
//2 — 33478695
//3 — 33486855
#define KEY_off_red 33441975
#define KEY_1 33444015
#define KEY_2 33478695
#define KEY_3 33486855
#define KEY_4 33435855
#define KEY_5 33468495
int f1,f2,b1,b2,t,a;
#define fan1 P1_4
#define bulb1 P1_5
#define fan2 P2_0
#define tube P2_1
#define bulb2 P2_2
#include <IRremote.h>
int RECV_PIN = P1_3;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
init_all();
off_all();
Serial.begin(9600);delay(1000);
Serial.println(“HAI”);
irrecv.enableIRIn(); // Start the receiver/’-;
}
void loop() {
while (!irrecv.decode(&results));
{
Serial.println(results.value);
check_ir_value();
irrecv.resume(); // Receive the next value
}
}
void check_ir_value(void)
{
if(results.value == KEY_1 )
{
Serial.print(“key1-“);
if(f1==1) {f1=0; Serial.println(“oFF”); digitalWrite(fan1 ,LOW); }
else {f1=1; Serial.println(“oN”); digitalWrite(fan1 ,HIGH); }
}
else if(results.value == KEY_2 )
{
Serial.print(“key2-“);
if(f2==1) {f2=0; Serial.println(“oFF”); digitalWrite(fan2 ,LOW); }
else {f2=1; Serial.println(“oN”); digitalWrite(fan2 ,HIGH); }
}
else if(results.value == KEY_3 )
{
Serial.print(“key3-“);
if(b1==1) {b1=0; Serial.println(“oFF”); digitalWrite(bulb1 ,LOW); }
else {b1=1; Serial.println(“oN”); digitalWrite(bulb1 ,HIGH); }
}
else if(results.value == KEY_4 )
{
Serial.print(“key4-“);
if(b2==1) {b2=0; Serial.println(“oFF”); digitalWrite(bulb2 ,LOW); }
else {b2=1; Serial.println(“oN”); digitalWrite(bulb2 ,HIGH); }
}
else if(results.value == KEY_5 )
{
Serial.print(“key5-“);
if(t==1) {t=0; Serial.println(“oFF”); digitalWrite(tube ,LOW); }
else {t=1; Serial.println(“oN”); digitalWrite(tube ,HIGH); }
}
else if(results.value == KEY_off_red )
{
Serial.print(“key-red-“);
if(a==1) {a=0; Serial.println(“oFF”); off_all(); }
else {a=1; Serial.println(“oN”); on_all(); }
}
}
void init_all(void)
{
pinMode(fan1,OUTPUT); pinMode(fan2,OUTPUT); pinMode(tube,OUTPUT);
pinMode(bulb1,OUTPUT); pinMode(bulb2,OUTPUT);
}
void off_all(void)
{
digitalWrite(fan1 ,LOW);digitalWrite(fan2 ,LOW);digitalWrite( tube,LOW);
digitalWrite( bulb1,LOW);digitalWrite(bulb2 ,LOW);
f1=0;f2=0;b1=0;b2=0;t=0;
}
void on_all(void)
{
f1=1;f2=1;b1=1;b2=1;t=1;
digitalWrite(fan1 ,HIGH); digitalWrite(fan2, HIGH); digitalWrite( tube,HIGH);
digitalWrite( bulb1,HIGH); digitalWrite(bulb2 ,HIGH);
}