I forgive everyone because I'm such a newbie that the paint hasn't even dried yet. I'm under some time constraints here. The attached sketch I've managed to cobble together over the past several weeks with absolutely NO experience with the Arduino code. So far, what's there works exactly how I need it to work. The very last piece I need to do is have the sketch bring a pin (2,3,4,5 or 6) to energize a relay twice a day. It needs to trip a relay, go through the routine in the code, then turn off and wait for the next time it activates. This should happen at 0000 UT and 1200 UT (based on the computer clock I'll compile it with.). So here's the picture. I need this to sit quietly and display the time and date. Twice in a 24 hour time period I need it to execute the calibration steps (outlined in the sketch)l, and when done, go back to displaying the clock until the next call. I have the CronoDot working fine. I just can't figure out how to set the times for the relay's. Have pitty on me. I started this project only 3 weeks ago. I'm actually pretty proud of what I've managed in that time.
_29_Jan_2017_PCF8523_ver_5.ino (30.1 KB)
First I'd put the whole mile of code in loop() into a function called say void doRelays() or something to make loop() a lot tidier.
Then in loop() call the waitStart() function to continuously show the time. So far so good.
Then set up an "if" to call doRelays() when tm.hour becomes 0 or 12. The trick there is that it needs to be when the time becomes either of those, not is either, since in the latter case it would run again and again until the hour incremented.
So you have a boolean flag say bool doneRelays initialised false, and your if to trigger doRelays() also needs to check the flag is false. After doRelays() you set the flag true so it's done it for that hour, and for a tm.hour of 1 or 13 you set it false again so it works on the next occurrence of 0 or 12.
Something like this:
bool doneRelays = false;
void setup()
{
// whatever
}
void loop()
{
waitStart(); //to show time like a clock
if ((tm.hour==00 || tm.hour=12) && doneRelays=false) // || means "or"
{
doRelays();
doneRelays=true;
}
if (tm.hour ==1 || tm.hour == 13)
{
doneRelays=false; // ready for next time
}
That's very rough and ready, I didn't examine your code line by line, but I reckon it's the general idea.
I'll look over that, and thank you. I'm using an adafruit Cronodot clock as the time keeper and also to show on the display when not executing the calibration steps. I'm using the Cronodot because we need time as accurate as possible and are trying to cover ourselves if there is a power outage. The excution of the code needs to happen at the same times. These units will be scattered all over the US. About 10 to start. Plans are 5 each additional for the next 4 years. We're concerned that the internal time keeper in the Arduino isn't accurate enough over a long period of time. Just some background, when finished, this device will be sending a calibration sequence to a sweep frequency spectrograph used for radio astronomy and the study of how the ionosphere affects the radio waves passing through it. Each spectrograph will be controlled remotely, but the calibration sequence we would like to be independent of the rest of the equipment. A GPS will be our next option, but as I'm struggling with just a simple clock, trying my hand at GPS code might be more than I can bite off at one time.
So, in the code above, how are the digital pins identified? I don't see any identified, pinMode set, or digitalWrite steps. And again, I do appreciate the help.
in the code above, how are the digital pins identified? I don't see any identified, pinMode set, or digitalWrite steps.
What was posted was an explanation of the logic needed, not the nuts and bolts of your program, which you need to add for yourself.
UKHeliBob:
What was posted was an explanation of the logic needed, not the nuts and bolts of your program
Thanks- I should maybe have added a note to that effect 