Countdown timer on LCD
How can I put a countdown timer from 300 second to 0 on a LCD?
Have fun with controlling everything!
https://letscontrolit.com/forum/
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
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)
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
Code: Select all
event,startTimer
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
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)
success after "lcd,2,13,300" command it types 300 right bottom corner but still "event,startTimer " not works
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
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
Code: Select all
on pulse#count do //
if [pulse#Total]>=3
PCFGPIO,1,1 // Start Relay
asyncEvent,startTimer // start the timer
endif
endon
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
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
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
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.
Code: Select all
Please put 3 coin
Inserted coins:[pulse#Total]
Rest time [var#300#d3]
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
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
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
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
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?
I do not know what to type to the rule, "Rest time [var#300#d3]" rule return 0
Code: Select all
LCD,4,1,"Rest time [var#300#d3]"
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
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
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
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
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 again . I already forced you too much, thank you again for all. These rules will help many people like me who don't have a programming background.Ath 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
Hello again me
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
Ok, this could be a solution:
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
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 usual )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
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.
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
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