Hello everyone I'm having difficulties and make a joining of commands one using RTC and the other activation of the servo motor that must be triggered according to the time it is placed.
Example
12:00 move 1 degree on the servo
12:43 move +1 degree on the servo.
THIS IS THE RTC
#include <Wire.h> // Includes Wire.h library
#include "RTClib.h" // includes library RTClib.h
RTC_DS1307 rtc; // create an RTC_DS1307 named rtc
Char daysOfTheWeek [7] [14] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
// the above line is an array with the days of the week
String zero (int n) {// function that checks if the number is less
// than ten, and if it is, add 0 before
If (n <10) {// Example: enter 5, exit 05-> 00:05:00
Return "0" + String (n); // how would it be-> 00: 00: 00
} Else {
Return String (n);
}
}
Void printAgora () {// function that prints -the current time
DateTime now = rtc.now (); // variable now of type DateTime and defines it as the time of rtc
Serial.print (String (daysOfTheWeek [now.dayOfTheWeek ()]) + "," + zero (now.day ()) + "/" + zero (now.month ()) + ));
Serial.print ("-");
Serial.println (zero (now.hour ()) + ":" + zero (now.minute ()) + ":" + zero (now.second ()));
// the top three lines print the information: day of the week, day / month / year - hh: mm: ss
}
Void setup () {
Serial.begin (9600);
If (! Rtc.begin ()) {// if! (No) start rtc prints the message.
Serial.println ("RTC not found.");
While (1);
}
//rtc.adjust is the function that sends the date and time to rtc:
Rtc.adjust (DateTime (2017, 10, 8, 19, 53, 0)); // uncomment this line to change the RTC time!
If (! Rtc.isrunning ()) {// if rtc! (Not) is working, adjust it with
Serial.println ("RTC is not working!"); // date and time of sketch compilation
Rtc.adjust (DateTime (F (__ DATE__), F (__ TIME__)));
}
}
Void loop () {
PrintAgora (); // executes the function that prints information
Delay (1000); // 1 second delay (1000ms), you should remove / comment on this line if you are using an LCD.
}
THE CODE ABOVE WORKS, I CAN NOT ACTIVATE THE ENGINE NOW
WHEN YOU FINISH THE DETERMINATOR TIMES IT DOES NOT WORK