#Include EEPROM.h
#Include EEPROM.h
#Include EEPROM.h
h>
#include <IRremote.h>
#include <SoftwareSerial.h>
SoftwareSerial BT_Serial(2, 3); // RX, TX
void setup(){
Serial.begin(9600);
BT_Serial.begin(9600);
pinMode(touch1, INPUT);
pinMode(touch2, INPUT);
pinMode(touch3, INPUT);
pinMode(touch4, INPUT);
pinMode(touch5, INPUT);
load1 = EEPROM.read(1);
load2 = EEPROM.read(2);
load3 = EEPROM.read(3);
load4 = EEPROM.read(4);
power = EEPROM.read(5);
delay(500);
}
void loop() {
if(digitalRead(touch1)==1){
if(flag1==0){flag1=1;
load1 = !load1;
EEPROM.write(1, load1);
delay(100);
}
}else{flag1=0;}
if(digitalRead(touch2)==1){
if(flag2==0){flag2=1;
load2 = !load2;
EEPROM.write(2, load2);
delay(100);
}
}else{flag2=0;}
if(digitalRead(touch3)==1){
if(flag3==0){flag3=1;
load3 = !load3;
EEPROM.write(3, load3);
delay(100);
}
}else{flag3=0;}
if(digitalRead(touch4)==1){
if(flag4==0){flag4=1;
load4 = !load4;
EEPROM.write(4, load4);
delay(100);
}
}else{flag4=0;}
if(digitalRead(touch5)==1){
if(flag5==0){flag5=1;
power = !power;
EEPROM.write(5, power);
delay(100);
}
}else{flag5=0;}
if(irrecv.decode(&results)){
Serial.println(results.value,HEX);
if(BT_Serial.available()>0){bt_data = BT_Serial.read();}
bt_data = '0';
if(power==1){
digitalWrite(Relay1, 1);
digitalWrite(Relay2, 1);
digitalWrite(Relay3, 1);
digitalWrite(Relay4, 1);
}else{
digitalWrite(Relay1, load1);
digitalWrite(Relay2, load2);
digitalWrite(Relay3, load3);
digitalWrite(Relay4, load4);
}
timer = timer+1;
if(timer>15){ timer=0;
BT_Serial.print(power); //send distance to MIT App
BT_Serial.print(";");
BT_Serial.print(load1); //send distance to MIT App
BT_Serial.print(";");
BT_Serial.print(load2); //send distance to MIT App
BT_Serial.print(";");
BT_Serial.print(load3); //send distance to MIT App
BT_Serial.print(";");
BT_Serial.print(load4); //send distance to MIT App
BT_Serial.println(";");
}
delay(50);
}