Countdown timer on LCD
Moderators: grovkillen, Stuntteam, TD-er
Countdown timer on LCD
Hello to all,
How can I put a countdown timer from 300 second to 0 on a LCD?
How can I put a countdown timer from 300 second to 0 on a LCD?
Re: Countdown timer on LCD
Code: Select all
on startTimer do
loopTimerSet,1,1,301 // stops after 301 seconds
endon
on Rules#Timer=1 do
Let,300,301-%eventvalue2%
Lcd,4,17,"[var#300#d3]" // lower right corner
endon
NB: Air-code (=untested)

Edit: Fixed typo...
Last edited by Ath on 19 Aug 2022, 22:28, edited 1 time in total.
/Ton (PayPal.me)
Re: Countdown timer on LCD
Sorry if it is important but my LCD is Display - LCD2004 (2*16). I cannot make your code work.Ath wrote: ↑19 Aug 2022, 18:49Start the timer using command "event,startTimer"Code: Select all
on startTimer do loopTimerStart,1,1,301 // stops after 301 seconds endon on Rules#Timer=1 do Let,300,301-%eventvalue2% Lcd,4,17,"[var#300#d3]" // lower right corner endon
NB: Air-code (=untested)![]()
Re: Countdown timer on LCD
I assumed form the other thread that you are using a LCD 4x20 display, so I put the countdown on line 4, column 17, change that to 2,13 and it should work.
/Ton (PayPal.me)
Re: Countdown timer on LCD
Actually I already have 2 different piece LCD 4x20 but I cannot make them work with nodemcu. It seems that issue would be another topic. Then I decided to try with 2x16 LCD then nodemcu works with it. Anyways my whole code is
Code: Select all
on startTimer do
loopTimerStart,1,1,301 // stops after 301 seconds
endon
on Rules#Timer=1 do
Let,300,301-%eventvalue2%
Lcd,2,13,"[var#300#d3]" // lower right corner
endon
on pulse#count do //
if [pulse#Total] >= 3
event,startTimer
endif
endon
Re: Countdown timer on LCD
I don't understand the last part of your rules.
But if you send an event via the command field on the Tools page like this:
Does it restart your timer?
But if you send an event via the command field on the Tools page like this:
Code: Select all
event,startTimer
Re: Countdown timer on LCD
I think you should test on the exact count of 3 coins to start the timer, but where are you resetting that total? Currently it should start again when adding another coin ( >=3).
You probably need to add event handlers for the start and stop buttons you have planned. (I didn't get to write code for your other request)
You probably need to add event handlers for the start and stop buttons you have planned. (I didn't get to write code for your other request)
/Ton (PayPal.me)
Re: Countdown timer on LCD
Command Output says OK but nothing happen at LCDTD-er wrote: ↑19 Aug 2022, 21:42 I don't understand the last part of your rules.
But if you send an event via the command field on the Tools page like this:Does it restart your timer?Code: Select all
event,startTimer
Re: Countdown timer on LCD
Does the display anything if you enter some text on Line 1 in the Device configuration? (may take up to Interval seconds to show up)
/Ton (PayPal.me)
Re: Countdown timer on LCD
I have not resetting button yet, I am trying to find out important part of the code, adding reset button is easy but right now I use primitive way clearing (>=3) for unplug the power sourceAth wrote: ↑19 Aug 2022, 21:47 I think you should test on the exact count of 3 coins to start the timer, but where are you resetting that total? Currently it should start again when adding another coin ( >=3).
You probably need to add event handlers for the start and stop buttons you have planned. (I didn't get to write code for your other request)

Re: Countdown timer on LCD
That looks fine, and what if you put some text in Line 1? Does that show on the display?
/Ton (PayPal.me)
Re: Countdown timer on LCD
So if you enter "lcd,2,13,300" in the Tools page and press Submit, does that also show on the display in the right bottom corner? Because that's what my rules should do as well 

/Ton (PayPal.me)
Re: Countdown timer on LCD
success after "lcd,2,13,300" command it types 300 right bottom corner but still "event,startTimer " not works
Re: Countdown timer on LCD
Ah, I've made a typo in my original script, change LoopTimerStart to LoopTimerSet and all should be fine 

/Ton (PayPal.me)
Re: Countdown timer on LCD
Code: Select all
on Rules#Timer=1 do
Let,300,301-%eventvalue2%
Lcd,2,13,"[var#300#d3]" // lower right corner
if %v300%=0 // last count results in 0
PCFGPIO,1,0
endif
endon
/Ton (PayPal.me)
Re: Countdown timer on LCD
Thank you, it woks. As you can see, when I put three coin to the coin acceptor, i am trying to activate timer for countdown but still no success by myself. I tried that code but no succeed can you look for me?Ath wrote: ↑19 Aug 2022, 22:57Code: Select all
on Rules#Timer=1 do Let,300,301-%eventvalue2% Lcd,2,13,"[var#300#d3]" // lower right corner if %v300%=0 // last count results in 0 PCFGPIO,1,0 endif endon
Code: Select all
on startTimer do
loopTimerSet,1,1,301 // stops after 301 seconds
endon
on pulse#count do //
if [pulse#Total] >= 3
event,startTimer >>>>>>>>>>>>>>>> Is that usage wrong?
endif
endon
on Rules#Timer=1 do
Let,300,301-%eventvalue2%
Lcd,2,13,"[var#300#d3]" // lower right corner
if %v300%=0 // last count results in 0
PCFGPIO,1,0
endif
endon
Re: Countdown timer on LCD
Code: Select all
on pulse#count do //
if [pulse#Total]>=3
PCFGPIO,1,1 // Start Relay
asyncEvent,startTimer // start the timer
endif
endon
To reset the total count once the timer is finished, you can adjust the code like this:
Code: Select all
on Rules#Timer=1 do
Let,300,301-%eventvalue2%
Lcd,2,13,"[var#300#d3]" // lower right corner
if %v300%=0 // last count results in 0
PCFGPIO,1,0 // Stop Relay
ResetPulseCounter // Restart counter
endif
endon
/Ton (PayPal.me)
Re: Countdown timer on LCD
My whole code becomeAth wrote: ↑20 Aug 2022, 11:50Besides adding the PCFGPIO command to enable the relay, I removed the spaces around the comparison in the 'if' statement, and used 'asyncEvent', to schedule it for execution, instead of 'event', that executes it immediately, but other than that, it does seem to be right.Code: Select all
on pulse#count do // if [pulse#Total]>=3 PCFGPIO,1,1 // Start Relay asyncEvent,startTimer // start the timer endif endon
To reset the total count once the timer is finished, you can adjust the code like this:Code: Select all
on Rules#Timer=1 do Let,300,301-%eventvalue2% Lcd,2,13,"[var#300#d3]" // lower right corner if %v300%=0 // last count results in 0 PCFGPIO,1,0 // Stop Relay ResetPulseCounter // Restart counter endif endon
Code: Select all
on startTimer do
loopTimerSet,1,1,301 // stops after 301 seconds
endon
on pulse#count do //
if [pulse#Total]>=3
PCFGPIO,1,1 // Start Relay
asyncEvent,startTimer // start the timer
endif
endon
on Rules#Timer=1 do
Let,300,301-%eventvalue2%
Lcd,2,13,"[var#300#d3]" // lower right corner
if %v300%=0 // last count results in 0
PCFGPIO,1,0 // Stop Relay
ResetPulseCounter // Restart counter
endif
endon
Code: Select all
asyncEvent,startTimer
Re: Countdown timer on LCD
I just pasted your last version of the rules into a test-unit, changed the LCD command to a LogEntry as I don't have such LCD connected, and issued the command setPulseCounterTotal,3
Then I watched the log via my serial monitor, and it happily started the countdown. With only 1 caveat: After 60 seconds, the timer was reset, as another pulse#count event was fired by the plugin!
Quick solution: Set the Interval to something > 300 sec. so no interfering events will reset the timer.
Better solution: Set a flag that it's running and do not reset the timer:
As a further improvement... I've split the start/stop action code each into separate rules (to hopefully improve readability of the code)
These new rules are called immediately using the event command instead of asyncEvent
NB: using the command asyncEvent,startTimer works with the same effect as triggering the timer, except it doesn't switch the PCFGPIO (that I also don't have connected
)
NB2: I'm using camelCase for commands and rule (=event) names for readability.
Then I watched the log via my serial monitor, and it happily started the countdown. With only 1 caveat: After 60 seconds, the timer was reset, as another pulse#count event was fired by the plugin!
Quick solution: Set the Interval to something > 300 sec. so no interfering events will reset the timer.
Better solution: Set a flag that it's running and do not reset the timer:
Code: Select all
on startTimer do
loopTimerSet,1,1,301 // stops after 301 seconds
endon
on pulse#count do //
if [pulse#Total]>=3 and %v301% = 0 // Don't allow to re-trigger when blocked
Let,301,1 // Block re-trigger until the timer has finished
Event,startAction
endif
endon
on Rules#Timer=1 do
Let,300,301-%eventvalue2%
Lcd,2,13,"[var#300#d3]" // lower right corner
if %v300%=0 // last count results in 0
Event,stopAction
Let,301,0 // Unblock
endif
endon
on startAction do
PCFGPIO,1,1 // Start Relay
asyncEvent,startTimer // start the timer
endon
on stopAction do
PCFGPIO,1,0 // Stop Relay
ResetPulseCounter // Restart counter
endon
These new rules are called immediately using the event command instead of asyncEvent
NB: using the command asyncEvent,startTimer works with the same effect as triggering the timer, except it doesn't switch the PCFGPIO (that I also don't have connected

NB2: I'm using camelCase for commands and rule (=event) names for readability.
/Ton (PayPal.me)
Re: Countdown timer on LCD
To make things a bit more explicit:
When I write that I send a command, like asyncEvent,startTimer, I type that command in the Command box of the Tools page, and click the Submit button.
When I write that I send a command, like asyncEvent,startTimer, I type that command in the Command box of the Tools page, and click the Submit button.
/Ton (PayPal.me)
Re: Countdown timer on LCD
Magnificent, hugs and hugs again. Thank you very muchhhhhhhh. It all works. I finally fix the 4x20 LCD screen and decided to use at that project.
at the beginning of the process i want the LCD to just show;
Line 1:Please put 3 coin (I already set it from Task Settings)
Line 2:inserted coin:0 >>>inserted coin:[pulse#Total] (I already set it from Task Settings)
after inserted coin, is it possible LCD shows the following
Line 1:Please put 3 coin
Line 2:inserted coin:0 >>>inserted coin:[pulse#Total]
Line 3:motor activated (i need to add that line)
Line 4:rest time >>>>>>Lcd,4,13,"[var#30#d3]" (i need to add beginning part of the the that line)
I know you tried so hard for me today but seems it is the final (i hope

Re: Countdown timer on LCD
You can put all that info on the Lines part of the LCD plugin, fixed a few typos:
The updating of the display can also be handled by the regular Interval setting, as I added that check using %v301% so you could set Interval to 1 to have an update every second.
Modified the rules for the changed display parameters and text:
Code: Select all
Please put 3 coin
Inserted coins:[pulse#Total]
Rest time [var#300#d3]
Modified the rules for the changed display parameters and text:
Code: Select all
on startTimer do
loopTimerSet,1,1,301 // stops after 301 seconds
endon
on pulse#count do //
if [pulse#Total]>=3 and %v301% = 0 // Don't allow to re-trigger when blocked
Let,301,1 // Block re-trigger until the timer has finished
Event,startAction
endif
endon
on Rules#Timer=1 do
Let,300,301-%eventvalue2%
// Lcd,4,11,"[var#300#d3]" // update display, handled by interval=1
if %v300%=0 // last count results in 0
Event,stopAction
Let,301,0 // Unblock
endif
endon
on startAction do
PCFGPIO,1,1 // Start Relay
LCD,3,1,"Motor activated"
asyncEvent,startTimer // start the timer
endon
on stopAction do
PCFGPIO,1,0 // Stop Relay
LCD,3,1," " // Clear text
ResetPulseCounter // Restart counter
endon
/Ton (PayPal.me)
Re: Countdown timer on LCD
Don't make him too enthusiastic about the capabilities of ESPEasy.
He just got the idea that he was finished and now you give him all kinds of ideas what else he could do to make his project even more fancy.
This way it will never be finished and before you know it, he starts programming, creating pull requests and then I have even more troubles to get it all to fit in the tiny flash of the ESP boards
He just got the idea that he was finished and now you give him all kinds of ideas what else he could do to make his project even more fancy.
This way it will never be finished and before you know it, he starts programming, creating pull requests and then I have even more troubles to get it all to fit in the tiny flash of the ESP boards

Re: Countdown timer on LCD
You ablolute right, after putting new codes to the rules i always have new ideas rest. Thanks for the magnificent firmwareTD-er wrote: ↑20 Aug 2022, 22:16 Don't make him too enthusiastic about the capabilities of ESPEasy.
He just got the idea that he was finished and now you give him all kinds of ideas what else he could do to make his project even more fancy.
This way it will never be finished and before you know it, he starts programming, creating pull requests and then I have even more troubles to get it all to fit in the tiny flash of the ESP boards![]()

Re: Countdown timer on LCD
Simply great, thanks for the all afford for me. Today and tomorrow i will test all the system.Ath wrote: ↑20 Aug 2022, 20:24 You can put all that info on the Lines part of the LCD plugin, fixed a few typos:The updating of the display can also be handled by the regular Interval setting, as I added that check using %v301% so you could set Interval to 1 to have an update every second.Code: Select all
Please put 3 coin Inserted coins:[pulse#Total] Rest time [var#300#d3]
Modified the rules for the changed display parameters and text:Code: Select all
on startTimer do loopTimerSet,1,1,301 // stops after 301 seconds endon on pulse#count do // if [pulse#Total]>=3 and %v301% = 0 // Don't allow to re-trigger when blocked Let,301,1 // Block re-trigger until the timer has finished Event,startAction endif endon on Rules#Timer=1 do Let,300,301-%eventvalue2% // Lcd,4,11,"[var#300#d3]" // update display, handled by interval=1 if %v300%=0 // last count results in 0 Event,stopAction Let,301,0 // Unblock endif endon on startAction do PCFGPIO,1,1 // Start Relay LCD,3,1,"Motor activated" asyncEvent,startTimer // start the timer endon on stopAction do PCFGPIO,1,0 // Stop Relay LCD,3,1," " // Clear text ResetPulseCounter // Restart counter endon
Re: Countdown timer on LCD
Hello, how can i display 4th line of the LCD (right now it is: Rest time [var#300#d3]) appear at the screen when the Event,startAction start (like line 3: LCD,3,1,"Motor activated") ? I tried LCD,4,1,"Rest time [var#300#d3]" but cannot work.Ath wrote: ↑20 Aug 2022, 20:24 You can put all that info on the Lines part of the LCD plugin, fixed a few typos:The updating of the display can also be handled by the regular Interval setting, as I added that check using %v301% so you could set Interval to 1 to have an update every second.Code: Select all
Please put 3 coin Inserted coins:[pulse#Total] Rest time [var#300#d3]
Modified the rules for the changed display parameters and text:Code: Select all
on startTimer do loopTimerSet,1,1,301 // stops after 301 seconds endon on pulse#count do // if [pulse#Total]>=3 and %v301% = 0 // Don't allow to re-trigger when blocked Let,301,1 // Block re-trigger until the timer has finished Event,startAction endif endon on Rules#Timer=1 do Let,300,301-%eventvalue2% // Lcd,4,11,"[var#300#d3]" // update display, handled by interval=1 if %v300%=0 // last count results in 0 Event,stopAction Let,301,0 // Unblock endif endon on startAction do PCFGPIO,1,1 // Start Relay LCD,3,1,"Motor activated" asyncEvent,startTimer // start the timer endon on stopAction do PCFGPIO,1,0 // Stop Relay LCD,3,1," " // Clear text ResetPulseCounter // Restart counter endon
Re: Countdown timer on LCD
If you want to change the text on line 4 depending on some condition, then you shouldn't set it in the Device configuration, but from rules. Exactly as you tried.
/Ton (PayPal.me)
Re: Countdown timer on LCD
I delete the line 4 from device configuration and type LCD,4,1,"Rest time [var#300#d3]" at rule but line 4 show Rest time 0". Do you know the exact rule for my requirements?
Re: Countdown timer on LCD
I do not know what to type to the rule, "Rest time [var#300#d3]" rule return 0
Re: Countdown timer on LCD
The suggested command is:
To explain the code...
LCD is the command
, is command parameter separator. However to remain compatible with older rules code, also <space> or <space><comma> or <comma><space> is accepted as a parameter separator.
For this reason, the last parameter is wrapped in quotes since it must contain a space.
Thus the parameters are:
4
1
"Rest time [var#300#d3]"
First is the linenr (I think...) and the second one the position on the line. (I think...)
The string in quotes will be replaced by the content of var#300 and formatted according to the d3 formatting syntax.
See the documentation for all formatting options: https://espeasy.readthedocs.io/en/lates ... red-values
Code: Select all
LCD,4,1,"Rest time [var#300#d3]"
LCD is the command
, is command parameter separator. However to remain compatible with older rules code, also <space> or <space><comma> or <comma><space> is accepted as a parameter separator.
For this reason, the last parameter is wrapped in quotes since it must contain a space.
Thus the parameters are:
4
1
"Rest time [var#300#d3]"
First is the linenr (I think...) and the second one the position on the line. (I think...)
The string in quotes will be replaced by the content of var#300 and formatted according to the d3 formatting syntax.
See the documentation for all formatting options: https://espeasy.readthedocs.io/en/lates ... red-values
Re: Countdown timer on LCD
Maybe I could not describe my problem exactly;TD-er wrote: ↑25 Aug 2022, 13:00 The suggested command is:To explain the code...Code: Select all
LCD,4,1,"Rest time [var#300#d3]"
LCD is the command
, is command parameter separator. However to remain compatible with older rules code, also <space> or <space><comma> or <comma><space> is accepted as a parameter separator.
For this reason, the last parameter is wrapped in quotes since it must contain a space.
Thus the parameters are:
4
1
"Rest time [var#300#d3]"
First is the linenr (I think...) and the second one the position on the line. (I think...)
The string in quotes will be replaced by the content of var#300 and formatted according to the d3 formatting syntax.
See the documentation for all formatting options: https://espeasy.readthedocs.io/en/lates ... red-values
Right now device settings of the LCD is;
Line 1:Please put 3 coin
Line 2:Inserted coins:[pulse#Total]
Line 3:
Line 4:Rest time [var#300#d3]
And the rule is:
Code: Select all
on startTimer do
loopTimerSet,1,1,301 // stops after 301 seconds
endon
on pulse#count do //
if [pulse#Total]>=3 and %v301% = 0 // Don't allow to re-trigger when blocked
Let,301,1 // Block re-trigger until the timer has finished
Event,startAction
endif
endon
on Rules#Timer=1 do
Let,300,301-%eventvalue2%
// Lcd,4,11,"[var#300#d3]" // update display, handled by interval=1
if %v300%=0 // last count results in 0
Event,stopAction
Let,301,0 // Unblock
endif
endon
on startAction do
GPIO,13,1 // Start Relay
LCD,3,1,"Motor activated"
asyncEvent,startTimer // start the timer
endon
on stopAction do
GPIO,13,0 // Stop Relay
LCD,3,1," " // Clear text
ResetPulseCounter // Restart counter
endon
_____________________________________________________________________________________________
I only want one changes from that configuration. I want to start display line 4 when
Code: Select all
on startAction do
Code: Select all
on startAction do
GPIO,13,1 // Start Relay
LCD,3,1,"Motor activated"
asyncEvent,startTimer // start the timer
endon
Code: Select all
LCD,4,1,"Rest time [var#300#d3]"
Code: Select all
on startAction do
GPIO,13,1 // Start Relay
LCD,3,1,"Motor activated"
LCD,4,1,"Rest time [var#300#d3]" >>>>>>>>>>>new added rule line
asyncEvent,startTimer // start the timer
endon
Re: Countdown timer on LCD
The timer wasn't updated, as it was from the regular Interval re-display. Have to re-enable displaying the remaining time in the Rules#Timer loop.
Here we go:
Here we go:
Code: Select all
on startTimer do
loopTimerSet,1,1,301 // stops after 301 seconds
endon
on pulse#count do //
if [pulse#Total]>=3 and %v301% = 0 // Don't allow to re-trigger when blocked
Let,301,1 // Block re-trigger until the timer has finished
Event,startAction
endif
endon
on Rules#Timer=1 do
Let,300,301-%eventvalue2%
Lcd,4,11,"[var#300#d3]" // update display
if %v300%=0 // last count results in 0
Event,stopAction
Let,301,0 // Unblock
endif
endon
on startAction do
GPIO,13,1 // Start Relay
LCD,3,1,"Motor activated"
LCD,4,1,"Rest time ___" // Waiting for the first update from the timer
asyncEvent,startTimer // start the timer
endon
on stopAction do
GPIO,13,0 // Stop Relay
LCD,3,1," " // Clear text
LCD,4,1," " // Clear text
ResetPulseCounter // Restart counter
endon
/Ton (PayPal.me)
Re: Countdown timer on LCD
Thank you very very much. That fits all my requirement. I have to put the project to the box as soon as possible before any new idea come to my mind againAth wrote: ↑25 Aug 2022, 14:27 The timer wasn't updated, as it was from the regular Interval re-display. Have to re-enable displaying the remaining time in the Rules#Timer loop.
Here we go:
Code: Select all
on startTimer do loopTimerSet,1,1,301 // stops after 301 seconds endon on pulse#count do // if [pulse#Total]>=3 and %v301% = 0 // Don't allow to re-trigger when blocked Let,301,1 // Block re-trigger until the timer has finished Event,startAction endif endon on Rules#Timer=1 do Let,300,301-%eventvalue2% Lcd,4,11,"[var#300#d3]" // update display if %v300%=0 // last count results in 0 Event,stopAction Let,301,0 // Unblock endif endon on startAction do GPIO,13,1 // Start Relay LCD,3,1,"Motor activated" LCD,4,1,"Rest time ___" // Waiting for the first update from the timer asyncEvent,startTimer // start the timer endon on stopAction do GPIO,13,0 // Stop Relay LCD,3,1," " // Clear text LCD,4,1," " // Clear text ResetPulseCounter // Restart counter endon


Re: Countdown timer on LCD
Great
Please post a photo once that box is closed (but the open box is also nice to see, I guess)

Please post a photo once that box is closed (but the open box is also nice to see, I guess)

/Ton (PayPal.me)
Re: Countdown timer on LCD
Hello again me

Unfortunately, when I was about to put the project in the box, a new idea came to my mind.Sorry about it

Code: Select all
on startTimer do
loopTimerSet,1,1,301 // stops after 301 seconds
endon
on pulse#count do //
if [pulse#Total]>=3 and %v301% = 0 // Don't allow to re-trigger when blocked
Let,301,1 // Block re-trigger until the timer has finished
Event,startAction
endif
endon
on Rules#Timer=1 do
Let,300,301-%eventvalue2%
Lcd,4,11,"[var#300#d3]" // update display
if %v300%=0 // last count results in 0
Event,stopAction
Let,301,0 // Unblock
endif
endon
on startAction do
GPIO,13,1 // Start Relay
LCD,3,1,"Motor activated"
LCD,4,1,"Rest time ___" // Waiting for the first update from the timer
asyncEvent,startTimer // start the timer
endon
on stopAction do
GPIO,13,0 // Stop Relay
LCD,3,1," " // Clear text
LCD,4,1," " // Clear text
ResetPulseCounter // Restart counter
endon
Code: Select all
on startTimer do
loopTimerSet,1,1,301 // stops after 301 seconds
endon
on pulse#count do //
if [pulse#Total]>=3 and %v11% = 0 and [Extender1#state] = 0// Don't allow to re-trigger when blocked
Let,301,1 // Block re-trigger until the timer has finished
Event,startAction
endif
endon
on Rules#Timer=1 do
Let,300,301-%eventvalue2%
Lcd,4,11,"[var#300#d3]" // update display
if %v300%=0 // last count results in 0
Event,stopAction
Let,301,0 // Unblock
endif
endon
on startAction do
GPIO,13,1 // Start Relay
LCD,3,1,"Motor activated"
LCD,4,1,"Rest time ___" // Waiting for the first update from the timer
asyncEvent,startTimer // start the timer
endon
on stopAction do
GPIO,13,0 // Stop Relay
LCD,3,1," " // Clear text
LCD,4,1," " // Clear text
ResetPulseCounter // Restart counter
endon
Code: Select all
[Extender1#state] = 0
I want to add second push button(push button2) and second relay(relay2). After putting 3 coin and if i press second push button i want countdown timer count from 100 second instead of 300 second and activate relay2. How can edit the rule?
Re: Countdown timer on LCD
Ok, this could be a solution:
- Add 3x "Switch input - PCF8574", and name them Start1, Start2 and Stop
- Start1 activates the current motor for 300 seconds
- Start2 activates another relay (I set it on GPIO12, you might need to change that) and named it Pump in the display
- Stop stops any ongoing action, as if the time-out countdown was reached
NB: The PCF8574 should get a different I2C address than the default 0x20, as it conflicts with the LCD, also on 0x20!
Once 3 coins are counted, the display shows "Choose action 1 or 2" -> The user should either press Start1 or Start2 buttons, Stop button isn't active yet
After choosing 1 or 2, the countdown starts, and the user can stop the action by pressing the Stop button (no visible clue for that on the display, though)
During countdown of the action, the Start1 and Start2 buttons are disabled
Code: Select all
on startTimer do
Let,302,%eventvalue1|300%+1 // Default value 300, increment by 1 for loopTimerSet offset
loopTimerSet,1,1,%v302% // stops after specified number of seconds
endon
on pulse#count do //
if [pulse#Total]>=3 and %v301% = 0 // Don't allow to re-trigger when blocked
Let,301,1 // Block re-trigger until the timer has finished
Let,303,1 // Enable Start buttons
LCD,3,1,"Coins received"
LCD,4,1,"Choose action 1 or 2"
endif
endon
on Rules#Timer=1 do
Let,300,%v302%-%eventvalue2%
Lcd,4,11,"[var#300#d3]" // update display
if %v300%=0 // last count results in 0
Event,stopAction
Let,301,0 // Unblock
Let,303,0 // Disable all buttons
endif
endon
on startAction do
Let,303,2 // Enable stop button, disable start buttons
if %v304%=1 // Action 1
GPIO,13,1 // Start Relay 1, GPIO 13
LCD,3,1,"Motor activated "
asyncEvent,startTimer=300 // start the timer for 300 seconds
endif
if %v304%=2 // Action 2
GPIO,12,1 // Start Relay 2, GPIO 12
LCD,3,1,"Pump activated " // Might need to update the text?
asyncEvent,startTimer=100 // start the timer for 100 seconds
endif
LCD,4,1,"Rest time ___ " // Waiting for the first update from the timer
endon
on stopAction do
if %v304%=1 // Action 1
GPIO,13,0 // Stop Relay 1, GPIO 13
endif
if %v304%=2 // Action 2
GPIO,12,0 // Stop Relay 2, GPIO 12
endif
LCD,3,1," " // Clear text
LCD,4,1," " // Clear text
ResetPulseCounter // Restart counter
Let,304,0 // No action
Let,300,0 // Clear remaining time
endon
on start1#state=0 do
if %v303%=1
Let,304,1 // Set action 1
asyncEvent,startAction
endif
endon
on start2#state=0 do
if %v303%=1
Let,304,2 // Set action 2
asyncEvent,startAction
endif
endon
on stop#state=0 do
if %v303%=2
event,stopAction
endif
endon

/Ton (PayPal.me)
Re: Countdown timer on LCD
Magnificent again, thanks for each letter of the script. It is working.Ath wrote: ↑04 Sep 2022, 16:02Ok, this could be a solution:
- Add 3x "Switch input - PCF8574", and name them Start1, Start2 and Stop
- Start1 activates the current motor for 300 seconds
- Start2 activates another relay (I set it on GPIO12, you might need to change that) and named it Pump in the display
- Stop stops any ongoing action, as if the time-out countdown was reached
NB: The PCF8574 should get a different I2C address than the default 0x20, as it conflicts with the LCD, also on 0x20!
Once 3 coins are counted, the display shows "Choose action 1 or 2" -> The user should either press Start1 or Start2 buttons, Stop button isn't active yet
After choosing 1 or 2, the countdown starts, and the user can stop the action by pressing the Stop button (no visible clue for that on the display, though)
During countdown of the action, the Start1 and Start2 buttons are disabled
(Untested, as usualCode: Select all
on startTimer do Let,302,%eventvalue1|300%+1 // Default value 300, increment by 1 for loopTimerSet offset loopTimerSet,1,1,%v302% // stops after specified number of seconds endon on pulse#count do // if [pulse#Total]>=3 and %v301% = 0 // Don't allow to re-trigger when blocked Let,301,1 // Block re-trigger until the timer has finished Let,303,1 // Enable Start buttons LCD,3,1,"Coins received" LCD,4,1,"Choose action 1 or 2" endif endon on Rules#Timer=1 do Let,300,%v302%-%eventvalue2% Lcd,4,11,"[var#300#d3]" // update display if %v300%=0 // last count results in 0 Event,stopAction Let,301,0 // Unblock Let,303,0 // Disable all buttons endif endon on startAction do Let,303,2 // Enable stop button, disable start buttons if %v304%=1 // Action 1 GPIO,13,1 // Start Relay 1, GPIO 13 LCD,3,1,"Motor activated " asyncEvent,startTimer=300 // start the timer for 300 seconds endif if %v304%=2 // Action 2 GPIO,12,1 // Start Relay 2, GPIO 12 LCD,3,1,"Pump activated " // Might need to update the text? asyncEvent,startTimer=100 // start the timer for 100 seconds endif LCD,4,1,"Rest time ___ " // Waiting for the first update from the timer endon on stopAction do if %v304%=1 // Action 1 GPIO,13,0 // Stop Relay 1, GPIO 13 endif if %v304%=2 // Action 2 GPIO,12,0 // Stop Relay 2, GPIO 12 endif LCD,3,1," " // Clear text LCD,4,1," " // Clear text ResetPulseCounter // Restart counter Let,304,0 // No action Let,300,0 // Clear remaining time endon on start1#state=0 do if %v303%=1 Let,304,1 // Set action 1 asyncEvent,startAction endif endon on start2#state=0 do if %v303%=1 Let,304,2 // Set action 2 asyncEvent,startAction endif endon on stop#state=0 do if %v303%=2 event,stopAction endif endon
)
I decided to move the project from esp8266 to esp32. Is there any differences to use 30 pin esp32 and 38 pin esp32 for usage. Actually i order both and i also order big 7 segment display for the TM1637 LED Display Module. I will share whole project with you after all is finished. Thanks for everything again.
Re: Countdown timer on LCD
Great to hear I didn't make too many typos
When using an ESP32, you probably won't need the PCF8574, as an ESP32 has more available GPIO pins.
The advantage of a 38 pin ESP32 module over a 30 pin module is that more pins are available to connect devices to. The 30 pin modules just have less pins connected to the outside world, making them more suitable for projects that require less GPIO pins.

When using an ESP32, you probably won't need the PCF8574, as an ESP32 has more available GPIO pins.
The advantage of a 38 pin ESP32 module over a 30 pin module is that more pins are available to connect devices to. The 30 pin modules just have less pins connected to the outside world, making them more suitable for projects that require less GPIO pins.
/Ton (PayPal.me)
Re: Countdown timer on LCD
Thank youAth wrote: ↑05 Sep 2022, 21:11 Great to hear I didn't make too many typos![]()
When using an ESP32, you probably won't need the PCF8574, as an ESP32 has more available GPIO pins.
The advantage of a 38 pin ESP32 module over a 30 pin module is that more pins are available to connect devices to. The 30 pin modules just have less pins connected to the outside world, making them more suitable for projects that require less GPIO pins.

Re: Countdown timer on LCD
Just one big warning about the 38 pin ESP32 boards....
The silkscreen is not always correct.
The pin next to the boot button is not 3V3!
The 3 pins next to the boot pin are directly connected to the flash chip.

Those marked "internal" are connected directly to the flash chip and should not be used to connect anything....
Well not unless you know what you're doing as I do have one on my desk here connected to my logic analyzer to measure the SPI flash clock frequency
The silkscreen is not always correct.
The pin next to the boot button is not 3V3!
The 3 pins next to the boot pin are directly connected to the flash chip.

Those marked "internal" are connected directly to the flash chip and should not be used to connect anything....
Well not unless you know what you're doing as I do have one on my desk here connected to my logic analyzer to measure the SPI flash clock frequency

Re: Countdown timer on LCD
Thanks for the that important warningTD-er wrote: ↑05 Sep 2022, 21:51 Just one big warning about the 38 pin ESP32 boards....
The silkscreen is not always correct.
The pin next to the boot button is not 3V3!
The 3 pins next to the boot pin are directly connected to the flash chip.
Those marked "internal" are connected directly to the flash chip and should not be used to connect anything....
Well not unless you know what you're doing as I do have one on my desk here connected to my logic analyzer to measure the SPI flash clock frequency![]()

Re: Countdown timer on LCD
Is it safe to use GPIO 16 to GPIO 33 for input and output without any restriction? I read the https://randomnerdtutorials.com/esp32-p ... nce-gpios/ page and it says GPIO 16 to GPIO 33 is safe. I need to ask you.TD-er wrote: ↑05 Sep 2022, 21:51 Just one big warning about the 38 pin ESP32 boards....
The silkscreen is not always correct.
The pin next to the boot button is not 3V3!
The 3 pins next to the boot pin are directly connected to the flash chip.
Those marked "internal" are connected directly to the flash chip and should not be used to connect anything....
Well not unless you know what you're doing as I do have one on my desk here connected to my logic analyzer to measure the SPI flash clock frequency![]()
Re: Countdown timer on LCD
GPIO 16 and 17 may be a bit tricky, but that's only a problem since the latest SDK updates.
The reason is that these can be used by PSRAM, which is present in the ESP32-WROVER modules.
The SDK can thus check these pins to see if PSRAM is present and thus the pins may be toggled at a high frequency during boot.
Due to the high frequency, the signal may appear to be "half" between GND and 3V3 and some transistors/sensors etc. may not like that at all.
See also the list in the ESPEasy documentation:
https://espeasy.readthedocs.io/en/lates ... e-on-esp32
The reason is that these can be used by PSRAM, which is present in the ESP32-WROVER modules.
The SDK can thus check these pins to see if PSRAM is present and thus the pins may be toggled at a high frequency during boot.
Due to the high frequency, the signal may appear to be "half" between GND and 3V3 and some transistors/sensors etc. may not like that at all.
See also the list in the ESPEasy documentation:
https://espeasy.readthedocs.io/en/lates ... e-on-esp32
Who is online
Users browsing this forum: No registered users and 13 guests