#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
boolean A_on_off = true;
boolean B_on_off = false;
boolean C_on_off = false;
boolean D_on_off = false;
int i=0;
int timer;
boolean A_timer;
boolean B_timer;
boolean C_timer;
boolean D_timer;
boolean t15 = false;
boolean t30 = false;
boolean t60 = false;
boolean t120 = false;
unsigned long timing;
unsigned long Time;
unsigned long Wait15=15000;
void setup() {
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A3, INPUT);
pinMode(A4, INPUT);
pinMode(A5, INPUT);
digitalWrite(3, true);
Serial.begin(9600);
mySwitch.enableReceive(0); // Receiver on interrupt 0 => that is pin #2
}
void loop() {
if (mySwitch.available()) {
if (mySwitch.getReceivedValue()==8377280)
{
A_on_off = !A_on_off;
digitalWrite(3, A_on_off);
delay(700);
}
if (mySwitch.getReceivedValue()==8377136)
{
B_on_off = !B_on_off;
digitalWrite(4, B_on_off);
delay(700);
}
if (mySwitch.getReceivedValue()==8377100)
{
C_on_off = !C_on_off;
digitalWrite(5, C_on_off);
delay(700);
}
if (mySwitch.getReceivedValue()==8377091)
{
D_on_off = !D_on_off;
digitalWrite(6, D_on_off);
delay(700);
}
if (mySwitch.getReceivedValue()==8377292)
{
timer=analogRead(A1);
if (analogRead(A2) > 500) { A_timer=true; } else { A_timer=false; }
if (analogRead(A3) > 500) { B_timer=true; } else { B_timer=false; }
if (analogRead(A4) > 500) { C_timer=true; } else { C_timer=false; }
if (analogRead(A5) > 500) { D_timer=true; } else { D_timer=false; }
if (timer > 1010 && timer < 1040){
timerstart();
t15=true;
Serial.println("Timer 15 Sec Start!");
}
if (timer > 990 && timer < 1000){
timerstart();
t30=true;
}
if (timer > 960 && timer < 980){
timerstart();
t60=true;
}
if (timer > 940 && timer < 959){
timerstart();
t120=true;
}
delay(700);
}
if (mySwitch.getReceivedValue()==8377148)
{
i=i+1;
if (i==4) i=0;
if (i== 1){
digitalWrite(4, true);
digitalWrite(5, false);
digitalWrite(6, false);
}
if (i==2){
digitalWrite(4, false);
digitalWrite(5, true);
digitalWrite(6, false);
}
if (i==3){
digitalWrite(4, false);
digitalWrite(5, false);
digitalWrite(6, true);
}
if (i==0){
digitalWrite(4, false);
digitalWrite(5, false);
digitalWrite(6, false);
}
delay(700);
}
if (mySwitch.getReceivedValue()==8377283)
{
digitalWrite(3, false);
digitalWrite(4, false);
digitalWrite(5, false);
digitalWrite(6, false);
delay(700);
}
if (mySwitch.getReceivedValue()==8377103)
{
digitalWrite(3, true);
digitalWrite(4, true);
digitalWrite(5, true);
digitalWrite(6, true);
delay(700);
}
mySwitch.resetAvailable();
}
if (t15==true){
if (millis() - timing > 15000){
timing = millis();
digitalWrite(3, false);
digitalWrite(4, false);
digitalWrite(5, false);
digitalWrite(6, false);
t15=false;
timing = 0;
}
}
if (t30==true){
if (millis() - timing > 30000){
timing = millis();
digitalWrite(3, false);
digitalWrite(4, false);
digitalWrite(5, false);
digitalWrite(6, false);
t30=false;
timing = 0;
}
}
if (t60==true){
if (millis() - timing > 60000){
timing = millis();
digitalWrite(3, false);
digitalWrite(4, false);
digitalWrite(5, false);
digitalWrite(6, false);
t60=false;
timing = 0;
}
}
if (t120==true){
if (millis() - timing > 120000){
timing = millis();
digitalWrite(3, false);
digitalWrite(4, false);
digitalWrite(5, false);
digitalWrite(6, false);
t120=false;
timing = 0;
}
}
}
void timerstart(){
if (A_timer == true){
digitalWrite(3, true);
digitalWrite(4, false);
digitalWrite(5, false);
digitalWrite(6, false);
}
if (B_timer == true){
digitalWrite(3, false);
digitalWrite(4, true);
digitalWrite(5, false);
digitalWrite(6, false);
}
if (C_timer == true){
digitalWrite(3, false);
digitalWrite(4, false);
digitalWrite(5, true);
digitalWrite(6, false);
}
if (D_timer == true){
digitalWrite(3, false);
digitalWrite(4, false);
digitalWrite(5, false);
digitalWrite(6, true);
}
}