ESP32Forth, new listing: configurable timer for housekeeper

35 views
Skip to first unread message

Marc Petremann

unread,
Jul 6, 2022, 6:55:21 PMJul 6
to
Hello,
After blinking an LED per timer, let's see another use case. Here, we are going to manage a timer in an intelligent way, this to help a housemaid. This ESP32Forth example application combines timer management and hardware interrupts.
https://github.com/MPETREMANN11/ESP32forth/blob/main/timers/configurable-timer.txt

Jos Ven

unread,
Jul 9, 2022, 6:23:27 AMJul 9
to
Also possible to blink a led:

cr .( poll-timers.fth)

0 [if]
blinker is called every 10 ms and does not waste 2000 ms
2 timers are used to switch the led on or off
sysledoff sysledOn should be defined for your situation
Notes:
1. Do not use it in time-critical situations
2. Uses ms@ for reading the current numer of milliseconds. ( - ms )
[then]

: start-timer ( timer - ) ms@ true rot 2! ;

: tElapsed? ( ms-elapsed timer - flag )
2@
if + ms@ < \ Time elapsed?
else 2drop false \ The timer is off
then ;

2variable tWaitLed2
2variable tLed2-On
2variable tLed2-Off

#100 value MsOn
#2000 value Msoff

: sysledoff ( - ) cr ." sysledoff " ;
: sysledOn ( - ) cr ." sysledOn " ;

: BlinkLed ( - )
MsOn tLed2-On tElapsed?
if sysledoff tLed2-On off
tLed2-Off start-timer
else Msoff tLed2-Off tElapsed?
if sysledOn tLed2-Off off
tLed2-On start-timer
then
then ;

: blinker ( - )
#3000 tWaitLed2 tElapsed?
if BlinkLed
then ;

: poll-app ( - )
sysledOff
tWaitLed2 start-timer
tLed2-On start-timer
tLed2-Off off
begin blinker #10 ms key?
until ;

poll-app
\ \s
Reply all
Reply to author
Forward
0 new messages