G+_Rud Dog Posted March 29, 2018 Share Posted March 29, 2018 PadreSj, stuck! Attempting to write a sketch via Arduino IDE for the ESP8266. The idea is to have a timer based on date and time ( 3-29-2018 and 08:45:25) which is grabbed using "NPT Web Server" code which I copied and pasted into my code. Have tried several attempts at this and come up short the "IF" loop seems to drop out early. Here is the idea; Set duration of time to 15 (minutes) if the date and time are equal to the set date and time then. Turn on the pin I/O of choice. if the duration of time is equal to zero then. Turn off pin I/O of choice. Check for next date and time to turn on/off I/O pin. Can send code I have so far just need to clean it up and place on Pastebin if you need to see what I have so far. Link to comment Share on other sites More sharing options...
G+_Rud Dog Posted March 29, 2018 Author Share Posted March 29, 2018 Think I might have solved it will post a link once I have presentable. Link to comment Share on other sites More sharing options...
G+_Rud Dog Posted March 30, 2018 Author Share Posted March 30, 2018 There is one minor problem the "IF" loop turns on the I/O pin every time it loops around so the out put reports the pin being turned on during the entire time it loops. if(HR == setHR && MN <= dur_Timer_MN){ //digitalWrite(output5, HIGH); //Turn on I/O pin Serial.print("Turn on I/O pin"); }else{ Serial.print("Turn off I/O pin"); //digitalWrite(output5, LOW); //Turn ff I/O pin and the serial monitor shows: 3-29-2018 9:47:31 Turn on I/O pin 3-29-2018 9:47:36 Turn on I/O pin 3-29-2018 9:47:41 Turn on I/O pin 3-29-2018 9:47:46 Here is the entire code with out any housekeeping : pastebin.com - [C++] Timer - Pastebin.com Link to comment Share on other sites More sharing options...
G+_John Sullivan Posted April 7, 2018 Share Posted April 7, 2018 I'm no expert at this, but I looked at your code on pastebin and see that you set: int setMN = 48; int dur_Timer_MN = setMN + 1; This defines your dur_Timer_MN as being 49 The serial output that you showed us shows the time is less than 9:49, so the LED ON is correct. Link to comment Share on other sites More sharing options...
G+_Rud Dog Posted April 9, 2018 Author Share Posted April 9, 2018 John Sullivan My apologies for not getting back to you got a bit tangled up trying to figure out the solution using AND,AND,AND,OR,OR. and this was consuming all my time. After reading what you wrote and reviewing the code you are correct. Seeing about implementing a new approach. Thank you. In essence, the new code will: Check and compare the hour to a set our if true move to the next condition. Compare the currents minutes to the length of time I want the I/O on if less than then continue to move to next condition. If the weekday is equal to 2 or the weekday is equal to 4 or if weekday is equal to 6 then one condition met. If all three conditions are met the I/O pin will be triggered on and for the duration of the current minutes to the length of time. Still working on ironing out the wrinkles. Link to comment Share on other sites More sharing options...
Recommended Posts