#include "RTClib.h"
#include <IRremote.h>
#include <Servo.h>
#define PIN_RECEIVER 2
int red = 5;
int pos = 0;
RTC_DS1307 rtc;
IRrecv receiver(PIN_RECEIVER);
Servo myservo;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
void setup () {
Serial.begin(9600);
pinMode (red, OUTPUT);
receiver.enableIRIn();
myservo.attach(9);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
}
void loop () {
if (receiver.decode()) {
translateIR();
receiver.resume();
}
}
void translateIR()
{
switch (receiver.decodedIRData.command) {
case 162:
Serial.println("ACTIVA EL SISTEMA");
digitalWrite(red, HIGH);
delay(2000);
Serial.println(receiver.decodedIRData.command);
break;
case 168:
myservo.write(180);
delay(1000);
myservo.write(0);
delay(1000);
myservo.attach(9);
break;
case 226:
digitalWrite(red, LOW);
break;
case 34:
DateTime now = rtc.now();
Serial.print("Current time: ");
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), 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(3000);
break;
}
}