Posted 3 March Hi, I was trying to do an logic with rtc, but I know i'm in the wrong way to do this, can someone give me a light about how can I do this on a better way? you insert an hour and minute to start a engine, and a hour and minute to stop this engine by the hmi. The way i'm doing this is: (ActualHour>=SetOnHour)&(ActualMinute>=SetOnMinute) == EngineON (ActualHour=SetOffHour)&(ActualMinute=SetOffMinute) == EngineOFF I know that are completely wrong because 1st: If i select 5AM to start and 5PM to stop, after 5PM, the system will start again. 2nd:Thinking you selected to start 5AM and stop 5PM, and know its 8AM, the system will start by hours normally, but if you have selected 20 minute and know its 15, the system will not work Share this post Link to post Share on other sites
Posted 3 March For each bound, and for the current time, convert hour and minute to minute-of-day. (zero to 1439.) Then you can do normal bounds checking on those integers. 1 person likes this Share this post Link to post Share on other sites
Posted 3 March Wow, how i didn't try this hahaha, felling like a dumbass I will do this and i come later to show the results and possible problems... thank you for the enlightenment Share this post Link to post Share on other sites
Posted 4 March Problem solved with the function(SetOffHour>=ActualHour)&(ActualHour>=SetOnHour) == engine (on/off) Btw, with this, another problem has appeared, this doesnt solve this question: When the SetOFFHour is lower than the ActualHour, so, if I select 5Am to Start and 4Am to stop, after 23:59, the system just stop and will only start at 5am again Share this post Link to post Share on other sites
Posted 5 March (edited) On 04/03/2023 at 11:38 PM, Rodrigo Balsalobre said: Problem solved with the function(SetOffHour>=ActualHour)&(ActualHour>=SetOnHour) == engine (on/off) Btw, with this, another problem has appeared, this doesnt solve this question: When the SetOFFHour is lower than the ActualHour, so, if I select 5Am to Start and 4Am to stop, after 23:59, the system just stop and will only start at 5am again i'm here again and the fuction to solve is (SetOffHour>=ActualHour>=SetOnHour) == engine (on/off) OR (SetOffHour>=0 && SetOffHour<=SetOnHour<=ActualHour) == engine on/off these two conditions solve the problem Edited 5 March by Rodrigo Balsalobre Share this post Link to post Share on other sites