Countdown timer on LCD

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
asuz
Normal user
Posts: 175
Joined: 31 Oct 2018, 18:22

Countdown timer on LCD

#1 Post by asuz » 19 Aug 2022, 17:22

Hello to all,
How can I put a countdown timer from 300 second to 0 on a LCD?

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Countdown timer on LCD

#2 Post by Ath » 19 Aug 2022, 18:49

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
Start the timer using command "event,startTimer"

NB: Air-code (=untested) 8-)
Edit: Fixed typo...
Last edited by Ath on 19 Aug 2022, 22:28, edited 1 time in total.
/Ton (PayPal.me)

asuz
Normal user
Posts: 175
Joined: 31 Oct 2018, 18:22

Re: Countdown timer on LCD

#3 Post by asuz » 19 Aug 2022, 20:42

Ath wrote: 19 Aug 2022, 18:49

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
Start the timer using command "event,startTimer"

NB: Air-code (=untested) 8-)
Sorry if it is important but my LCD is Display - LCD2004 (2*16). I cannot make your code work.

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Countdown timer on LCD

#4 Post by Ath » 19 Aug 2022, 21:07

asuz wrote: 19 Aug 2022, 20:42 Sorry if it is important but my LCD is Display - LCD2004 (2*16). I cannot make your code work.
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)

asuz
Normal user
Posts: 175
Joined: 31 Oct 2018, 18:22

Re: Countdown timer on LCD

#5 Post by asuz » 19 Aug 2022, 21:26

Ath wrote: 19 Aug 2022, 21:07
asuz wrote: 19 Aug 2022, 20:42 Sorry if it is important but my LCD is Display - LCD2004 (2*16). I cannot make your code work.
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.
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
at rule 1 but cannot make it work again ?

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Countdown timer on LCD

#6 Post by TD-er » 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:

Code: Select all

event,startTimer 
Does it restart your timer?

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Countdown timer on LCD

#7 Post by Ath » 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)
/Ton (PayPal.me)

asuz
Normal user
Posts: 175
Joined: 31 Oct 2018, 18:22

Re: Countdown timer on LCD

#8 Post by asuz » 19 Aug 2022, 21:48

TD-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:

Code: Select all

event,startTimer 
Does it restart your timer?
Command Output says OK but nothing happen at LCD

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Countdown timer on LCD

#9 Post by Ath » 19 Aug 2022, 21:57

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)

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Countdown timer on LCD

#10 Post by Ath » 19 Aug 2022, 21:59

And what does the I2C scan from the Tools page show?
/Ton (PayPal.me)

asuz
Normal user
Posts: 175
Joined: 31 Oct 2018, 18:22

Re: Countdown timer on LCD

#11 Post by asuz » 19 Aug 2022, 22:00

Ath 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)
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 source :)

asuz
Normal user
Posts: 175
Joined: 31 Oct 2018, 18:22

Re: Countdown timer on LCD

#12 Post by asuz » 19 Aug 2022, 22:02

Ath wrote: 19 Aug 2022, 21:59 And what does the I2C scan from the Tools page show?
Attachments
ic2.png
ic2.png (32.9 KiB) Viewed 12563 times

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Countdown timer on LCD

#13 Post by Ath » 19 Aug 2022, 22:06

That looks fine, and what if you put some text in Line 1? Does that show on the display?
/Ton (PayPal.me)

asuz
Normal user
Posts: 175
Joined: 31 Oct 2018, 18:22

Re: Countdown timer on LCD

#14 Post by asuz » 19 Aug 2022, 22:08

Ath wrote: 19 Aug 2022, 22:06 That looks fine, and what if you put some text in Line 1? Does that show on the display?
Yes

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Countdown timer on LCD

#15 Post by Ath » 19 Aug 2022, 22:14

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)

asuz
Normal user
Posts: 175
Joined: 31 Oct 2018, 18:22

Re: Countdown timer on LCD

#16 Post by asuz » 19 Aug 2022, 22:16

Ath wrote: 19 Aug 2022, 22:14 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 :)
success after "lcd,2,13,300" command it types 300 right bottom corner but still "event,startTimer " not works

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Countdown timer on LCD

#17 Post by Ath » 19 Aug 2022, 22:26

Ah, I've made a typo in my original script, change LoopTimerStart to LoopTimerSet and all should be fine :oops:
/Ton (PayPal.me)

asuz
Normal user
Posts: 175
Joined: 31 Oct 2018, 18:22

Re: Countdown timer on LCD

#18 Post by asuz » 19 Aug 2022, 22:33

Ath wrote: 19 Aug 2022, 22:26 Ah, I've made a typo in my original script, change LoopTimerStart to LoopTimerSet and all should be fine :oops:
Hugs to you thank you it works. Last thing for tonight; how can i relay off (PCFGPIO,1,0) when counter reach to zero.

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Countdown timer on LCD

#19 Post by Ath » 19 Aug 2022, 22:57

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)

asuz
Normal user
Posts: 175
Joined: 31 Oct 2018, 18:22

Re: Countdown timer on LCD

#20 Post by asuz » 20 Aug 2022, 11:07

Ath wrote: 19 Aug 2022, 22:57

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?

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

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Countdown timer on LCD

#21 Post by Ath » 20 Aug 2022, 11:50

Code: Select all

on pulse#count do //
  if [pulse#Total]>=3
    PCFGPIO,1,1 // Start Relay
    asyncEvent,startTimer // start the timer
  endif
endon
Besides 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.

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)

asuz
Normal user
Posts: 175
Joined: 31 Oct 2018, 18:22

Re: Countdown timer on LCD

#22 Post by asuz » 20 Aug 2022, 12:49

Ath wrote: 20 Aug 2022, 11:50

Code: Select all

on pulse#count do //
  if [pulse#Total]>=3
    PCFGPIO,1,1 // Start Relay
    asyncEvent,startTimer // start the timer
  endif
endon
Besides 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.

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
My whole code become

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
But it didnot bring the countdown to the secreen. It seems

Code: Select all

asyncEvent,startTimer
doesnot work

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Countdown timer on LCD

#23 Post by Ath » 20 Aug 2022, 14:10

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:

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
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.
/Ton (PayPal.me)

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Countdown timer on LCD

#24 Post by Ath » 20 Aug 2022, 14:13

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.
/Ton (PayPal.me)

asuz
Normal user
Posts: 175
Joined: 31 Oct 2018, 18:22

Re: Countdown timer on LCD

#25 Post by asuz » 20 Aug 2022, 19:01

Ath wrote: 20 Aug 2022, 14:13 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.
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 :D )

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Countdown timer on LCD

#26 Post by Ath » 20 Aug 2022, 20:24

You can put all that info on the Lines part of the LCD plugin, fixed a few typos:

Code: Select all

Please put 3 coin
Inserted coins:[pulse#Total]

Rest time [var#300#d3]
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

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)

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Countdown timer on LCD

#27 Post by TD-er » 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 ;)

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Countdown timer on LCD

#28 Post by Ath » 20 Aug 2022, 22:38

:lol: :lol: :lol:
/Ton (PayPal.me)

asuz
Normal user
Posts: 175
Joined: 31 Oct 2018, 18:22

Re: Countdown timer on LCD

#29 Post by asuz » 21 Aug 2022, 09:33

TD-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 ;)
You ablolute right, after putting new codes to the rules i always have new ideas rest. Thanks for the magnificent firmware :D

asuz
Normal user
Posts: 175
Joined: 31 Oct 2018, 18:22

Re: Countdown timer on LCD

#30 Post by asuz » 21 Aug 2022, 09:35

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:

Code: Select all

Please put 3 coin
Inserted coins:[pulse#Total]

Rest time [var#300#d3]
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

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
Simply great, thanks for the all afford for me. Today and tomorrow i will test all the system.

asuz
Normal user
Posts: 175
Joined: 31 Oct 2018, 18:22

Re: Countdown timer on LCD

#31 Post by asuz » 24 Aug 2022, 15:09

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:

Code: Select all

Please put 3 coin
Inserted coins:[pulse#Total]

Rest time [var#300#d3]
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

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.

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Countdown timer on LCD

#32 Post by Ath » 24 Aug 2022, 16:38

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)

asuz
Normal user
Posts: 175
Joined: 31 Oct 2018, 18:22

Re: Countdown timer on LCD

#33 Post by asuz » 24 Aug 2022, 22:44

Ath wrote: 24 Aug 2022, 16:38 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.
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?

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Countdown timer on LCD

#34 Post by Ath » 24 Aug 2022, 22:49

asuz wrote: 24 Aug 2022, 22:44 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?
Most likely, the content of var 300 is 0.
/Ton (PayPal.me)

asuz
Normal user
Posts: 175
Joined: 31 Oct 2018, 18:22

Re: Countdown timer on LCD

#35 Post by asuz » 25 Aug 2022, 12:52

Ath wrote: 24 Aug 2022, 22:49
asuz wrote: 24 Aug 2022, 22:44 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?
Most likely, the content of var 300 is 0.
I do not know what to type to the rule, "Rest time [var#300#d3]" rule return 0

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Countdown timer on LCD

#36 Post by TD-er » 25 Aug 2022, 13:00

The suggested command is:

Code: Select all

LCD,4,1,"Rest time [var#300#d3]"
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

asuz
Normal user
Posts: 175
Joined: 31 Oct 2018, 18:22

Re: Countdown timer on LCD

#37 Post by asuz » 25 Aug 2022, 13:48

TD-er wrote: 25 Aug 2022, 13:00 The suggested command is:

Code: Select all

LCD,4,1,"Rest time [var#300#d3]"
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
Maybe I could not describe my problem exactly;

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
With that configuration it works very well, especially thanks to you and Ath.
_____________________________________________________________________________________________

I only want one changes from that configuration. I want to start display line 4 when

Code: Select all

on startAction do
like rule

Code: Select all

on startAction do
  GPIO,13,1 // Start Relay
  LCD,3,1,"Motor activated"
  asyncEvent,startTimer // start the timer
endon
so I delete line 4 from LCD device settings and add

Code: Select all

LCD,4,1,"Rest time [var#300#d3]"
to the

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
But that rule returns the line 4 of the LCD is Rest time 0 always without countdown. This is my problem how can I solve that?

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Countdown timer on LCD

#38 Post by Ath » 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
/Ton (PayPal.me)

asuz
Normal user
Posts: 175
Joined: 31 Oct 2018, 18:22

Re: Countdown timer on LCD

#39 Post by asuz » 25 Aug 2022, 15:29

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
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 :D . 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. :idea:

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Countdown timer on LCD

#40 Post by Ath » 25 Aug 2022, 15:32

Great :)

Please post a photo once that box is closed (but the open box is also nice to see, I guess) 8-)
/Ton (PayPal.me)

asuz
Normal user
Posts: 175
Joined: 31 Oct 2018, 18:22

Re: Countdown timer on LCD

#41 Post by asuz » 25 Aug 2022, 16:12

Ath wrote: 25 Aug 2022, 15:32 Great :)

Please post a photo once that box is closed (but the open box is also nice to see, I guess) 8-)
Of course I will :D

asuz
Normal user
Posts: 175
Joined: 31 Oct 2018, 18:22

Re: Countdown timer on LCD

#42 Post by asuz » 01 Sep 2022, 11:11

Ath wrote: 25 Aug 2022, 15:32 Great :)

Please post a photo once that box is closed (but the open box is also nice to see, I guess) 8-)
Hello again me :D
Unfortunately, when I was about to put the project in the box, a new idea came to my mind.Sorry about it :oops: My orijinal 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
  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
I add Switch input - PCF8574 to the nodemcu and add a push button and two channel relay. Then my rule become ;

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
as you can see I add the

Code: Select all

 [Extender1#state] = 0 
script to the rule. When I add the 3 coin and press the push button the motor activated for 300 second at the relay1.
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?

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Countdown timer on LCD

#43 Post by Ath » 04 Sep 2022, 16:02

asuz wrote: 01 Sep 2022, 11:11 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?
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
(Untested, as usual ;))
/Ton (PayPal.me)

asuz
Normal user
Posts: 175
Joined: 31 Oct 2018, 18:22

Re: Countdown timer on LCD

#44 Post by asuz » 05 Sep 2022, 19:53

Ath wrote: 04 Sep 2022, 16:02
asuz wrote: 01 Sep 2022, 11:11 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?
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
(Untested, as usual ;))
Magnificent again, thanks for each letter of the script. It is working.
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.

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Countdown timer on LCD

#45 Post by Ath » 05 Sep 2022, 21:11

Great to hear I didn't make too many typos :lol:

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)

asuz
Normal user
Posts: 175
Joined: 31 Oct 2018, 18:22

Re: Countdown timer on LCD

#46 Post by asuz » 05 Sep 2022, 21:27

Ath wrote: 05 Sep 2022, 21:11 Great to hear I didn't make too many typos :lol:

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.
Thank you :D

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Countdown timer on LCD

#47 Post by TD-er » 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.
Image
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 ;)

asuz
Normal user
Posts: 175
Joined: 31 Oct 2018, 18:22

Re: Countdown timer on LCD

#48 Post by asuz » 05 Sep 2022, 22:51

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 ;)
Thanks for the that important warning :idea:

asuz
Normal user
Posts: 175
Joined: 31 Oct 2018, 18:22

Re: Countdown timer on LCD

#49 Post by asuz » 26 Sep 2022, 14:00

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.
Image
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
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Countdown timer on LCD

#50 Post by TD-er » 26 Sep 2022, 21:17

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

Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests