|
Forum Index : Microcontroller and PC projects : Testing for a particular time period
| Author | Message | ||||
| OA47 Guru Joined: 11/04/2012 Location: AustraliaPosts: 1036 |
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: 84 |
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: 6455 |
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: 3016 |
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: 1036 |
Thankyou all, I will use the string comparison. OA47 |
||||
| PhenixRising Guru Joined: 07/11/2023 Location: United KingdomPosts: 1730 |
"your version of logic" 🤣😂🤣😂 |
||||
| Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 8568 |
This is only one of the reasons why it's difficult to properly check your own code. You *know* that a particular logic stream is correct when it will stand out like a beacon to someone else that it's wrong. :( Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
| PhenixRising Guru Joined: 07/11/2023 Location: United KingdomPosts: 1730 |
|
||||
| Andrew_G Guru Joined: 18/10/2016 Location: AustraliaPosts: 874 |
Hi Graeme, You kindly gifted me some monitors and cables via Big Mick a few months back. Thanks. Another solution to your issue is to use a Light Dependant Resistor (LDR) (e.g. Jaycar # RD3480) to measure the ambient light. I use them on "everything", especially in my sleeping quarters/my side of the bed. With a little bit of calibration you can get three levels, bright/normal/dark, and set BACKLIGHT accordingly. Use SETTICK to check the resistance every second and it responds well. Happy to post more details. Cheers, Andrew |
||||
| OA47 Guru Joined: 11/04/2012 Location: AustraliaPosts: 1036 |
Andrew you are very welcome. It is a bit of a pity that so much stuff had to be sent to waste but that was the way it was. OA47 |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2026 |