#include <RTClib.h>
#include <IRremote.h>
#include <Servo.h>
int PIN_RECEIVER = 2;
int led = 4;
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Domingo", "Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sabado"};
IRrecv ir(PIN_RECEIVER);
Servo myservo;
void setup () {
Serial.begin(115200);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
pinMode(led, OUTPUT);
ir.enableIRIn();
myservo.detach();
Serial.println();
Serial.println("ACTIVAR SISTEMA.PULSE EL BOTÓN ROJO");
}
void loop()
{
// Checks received an IR signal
if (ir.decode()) {
translateIR();
ir.resume(); // Receive the next value
}
}
void translateIR()
{
// Takes command based on IR code received
switch (ir.decodedIRData.command) {
case 162:
Serial.println("SISTEMA ACTIVADO");
digitalWrite(led, HIGH);
myservo.attach(3);
break;
case 168:
myservo.write(180);
delay(200);
myservo.write(0);
delay(200);
myservo.write(180);
delay(200);
myservo.write(0);
delay(200);
break;
case 226:
myservo.detach();
digitalWrite(led, LOW);
break;
case 34:
DateTime now = rtc.now();
Serial.print("Actual: ");
Serial.print(" (");
Serial.print(now.day(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.year(), DEC);
Serial.print(" ");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
delay(500);
break;
}
}