I have recently been attempting to use an RTC module which has the DS1302 chip to control a signal to an LED. I'd like to send a signal at a specific time of day, every day for 2 hours. I have so far used this code:
// Program: Date and time with RTC DS1302 module
// Amendment and adaptation: Arduino and Cia
//
// Based on the original program Krodal and virtuabotixRTC library
// Load the virtuabotixRTC library
#include <virtuabotixRTC.h>
// Determine the pins connected to the module
// myRTC (clock, data, RST)
virtuabotixRTC myRTC (6, 7, 8);
void setup ()
{
Serial.begin
(9600); // date and time of initial Information
// After to set the entire information, comment the following line
// (seconds, minutes, hours, day of week, day of month, month, year)
myRTC.setDS1302Time (50, 01, 18, 4, 9, 10, 2015);
}
void loop ()
{
// Reads the information from the CI
myRTC.updateTime ();
// Print the details in serial monitor
Serial.print
("Data"); // Call the routine that prints the day of the week
imprime_dia_da_semana (myRTC.dayofweek);
Serial.print (",");
Serial.print (myRTC.dayofmonth);
Serial.print ("/");
Serial.print (myRTC.month);
Serial.print ("/");
Serial.print (myRTC.year);
Serial.print ("");
Serial.print
("Time"); // Adds a 0 if the time value is <10
if (myRTC.hours <10)
{
Serial.print ("0");
}
Serial.print (myRTC.hours);
Serial.print
(":"); // Adds a 0 if the value of the minutes is <10
if (myRTC.minutes <10)
{
Serial.print ("0");
}
Serial.print (myRTC.minutes);
Serial.print
(":"); // Adds a 0 if the value of the latter is <10
if (myRTC.seconds <10)
{
Serial.print ("0");
}
Serial.println (myRTC.seconds);
delay (1000);
}
void imprime_dia_da_semana (int day)
{
switch (day)
{
case 1:
Serial.print
("Sunday");
break; case 2:
Serial.print
("Second");
break; case 3:
Serial.print
("Terca");
break; case 4:
Serial.print
("Wednesday");
break; case 5:
Serial.print
("Quinta");
break; case 6:
Serial.print
("Friday");
break; case 7:
Serial.print
("Saturday"); break;
}
}
Which allows me to read the time in the serial monitor, but I am little stuck for how to read the serial monitor in order to send a signal. I know it will be something I need to write in the void loop...
Ah I see what you're saying. So if for example I introduce the LED as pin 13 saying pinMode(13, OUTPUT); at the beginning of the sketch, I could write in the void loop:
in an attempt to send a signal to the LED for 5 seconds at 18.02, however the LED doesn't seem to be responding, though it does flash momentarily on the 18.00 mark I think
am now also having the problem that the serial monitor is telling me it is the original time I set the RTC even though I have tried changing the time and re-uploading the code a bunch of times...