|
Forum Index : Microcontroller and PC projects : Testing for a particular time period
| Author | Message | ||||
| OA47 Guru Joined: 11/04/2012 Location: AustraliaPosts: 1016 |
I am using many displays that are active 24/7 and would like to lower the backlight during evening hours. I have used a test to look for 07:00:00 and 19:00:00 time stamps which works OK but occasionally that time stamp is missed due to other operations of the program. I would like to test if the time is past 07:00:00 and 19:00:00 to reduce or increase the backlight. I vagally remember discussions of an EPOC command but I can't find any mention in the handbooks. Would this be the direction I should head? Regards OA47 |
||||
| Andy-g0poy Regular Member Joined: 07/03/2023 Location: United KingdomPosts: 83 |
EPOCH(DATETIME$) and NOW Print EPOCH(NOW) Page 187 DATETIME$(n) returns the date time string fromthe epoch number n page 185 Using the pdf manual MMBasic BASIC Interpreter Ver 6.01.00 Andy |
||||
TassyJim![]() Guru Joined: 07/08/2011 Location: AustraliaPosts: 6437 |
Time$ is a string and you can compare strings ' IF TIME$ >= "07:00:00" AND TIME$ < "19:00:00" THEN backlight = 100 ELSE backlight = 20 ENDIF VK7JH MMedit |
||||
| phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2951 |
That is clever, easier than Epoch. > TIME$ = "06:55" : ? TIME$ >= "07:00:00" AND TIME$ < "19:00:00" 0 > TIME$ = "07:05" : ? TIME$ >= "07:00:00" AND TIME$ < "19:00:00" 1 > TIME$ = "18:55" : ? TIME$ >= "07:00:00" AND TIME$ < "19:00:00" 1 > TIME$ = "19:05" : ? TIME$ >= "07:00:00" AND TIME$ < "19:00:00" 0 > > night = 19*60*60 > day = 7*60*60 > aDay = 24*60*60 > if epoch(now) mod aDay > night then backlight 10 > if epoch(now) mod aDay > day then backlight 100 Edited 2026-01-23 12:29 by phil99 |
||||
| greybeard Senior Member Joined: 04/01/2010 Location: AustraliaPosts: 178 |
As a general guideline for programming limit or range logic I'd suggest checking for > or < as appropriate unless circumstances preclude doing so. ie not just = to. A lot more people can program when the real world behaves as they expect their virtual world to behave. A good programmer should strive to program for when the real world is real and things don't behave in a virtual manner. ie program for the worst case, not the best case especially if your version of logic says it can't happen, it will. |
||||
| OA47 Guru Joined: 11/04/2012 Location: AustraliaPosts: 1016 |
Thankyou all, I will use the string comparison. OA47 |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2026 |