How would I code a RTC to run a program starting at 11:30pm and stopping at 5:30am? This is for a traffic project where only yellow stop lights flash during this time period
The answer would depend on what type of RTC you have.
However, the Arduino Time library makes it easy to compare dates and times, and take action.
You can learn to use it without using an RTC (using the Arduino functions instead), and add the RTC later to keep accurate track of the time.
if(minutesAfterMidnight > 330 && minutesAfterMidnight < 1410) runTheTraficLightCode;
else runTheYellowLightCode;
Please keep your project questions in one place.
https://forum.arduino.cc/index.php?topic=549847.0
Leo..
The RTC im using is a DS1307, and I'm really new to arduino and programming. My teacher knows nothing and hasn't taught anything based upon this.
We recommend that beginners work through the simple projects that come with the Arduino development software, to learn the language and special features of the Arduino. Blink an LED, read a button, a voltage, the temperature, etc.
If you don't, expect endless frustration with your rather advanced traffic light project.
jremington:
The answer would depend on what type of RTC you have.However, the Arduino Time library makes it easy to compare dates and times, and take action.
You can learn to use it without using an RTC (using the Arduino functions instead), and add the RTC later to keep accurate track of the time.
The RTC I have is a DS1307. How would i incorporate the time functions to run it during those times, and include the RTC after
Reading the RTC every loop() and calculating the minutes after midnight shouldn't be that hard.
Plenty of examples on the net, like this one.
Here we try to help you with code/homework (don't write it for you).
Post your attempt (inside code tags).
Leo..
How would i incorporate the time functions to run it during those times, and include the RTC after
First, learn to use the Time library. There are many examples on line. It works and will do what you want, but does not keep accurate time. You don't need to keep accurate time for a demonstration project anyway.
When you understand how to use the Time library, you can simply connect the RTC to the Arduino, set the RTC time and date, then use the "setSyncProvider" function to tell the Time library to use the RTC for more accurate timekeeping.
Note: The DS1307 is not very accurate, either. Most people use the DS3231.