Progress bar for display

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
User avatar
ohaldi
Normal user
Posts: 61
Joined: 31 Jan 2020, 09:10
Location: Switzerland

Progress bar for display

#1 Post by ohaldi » 21 Jul 2022, 21:08

Hello. I want to display a progress bar. In my case I use a 16x2 LCD.
I would like each character (star) to display a 10 second delay.
However, I would like my two buttons to remain active while the progress bar is displayed. Does anyone have an example?
it would be nice if the character was a block.

I based myself on the following idea.
on System#Boot do // activé lors de la mise sous tension
LCD,1,1,"Progress bar"
timerSet,1,5 //Set Timer 1
endon

on Rules#Timer=1 do
LCD,1,1,*
timerSet,2,10 //Set Timer 2
endon

on Rules#Timer=2 do
LCD,1,1,**
timerSet,3,10 //Set Timer 3
endon

on Rules#Timer=3 do
LCD,1,1,***
timerSet,4,10 //Set Timer 4
endon

on Rules#Timer=4 do
LCD,1,1,****
timerSet,1,10 //Back to Timer 1
endon

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

Re: Progress bar for display

#2 Post by Ath » 21 Jul 2022, 21:46

That can be done a bit simpler:

Code: Select all

on System#Boot do
  AsyncEvent,Progress
endon

on Progress do
  let 1,%eventvalue1|10% // Default n = 10
  LCD,1,1,"Progress bar"
  LoopTimerSet,1,10,%v1% // Repeat timer 1 every 10 sec. for n times
endon

on Rules#Timer=1 do
  LCD,1,1,{substring:0:%eventvalue2%:****************} // Use enough * to allow all n loops to be shown
endon
End you can send command "AsyncEvent,Progress" (10 steps) or "AsyncEvent,Progress=6" (6 steps) from anywhere (rules, Tools page, via url) to start the progress bar with an optional count of 10 seconds
/Ton (PayPal.me)

User avatar
ohaldi
Normal user
Posts: 61
Joined: 31 Jan 2020, 09:10
Location: Switzerland

Re: Progress bar for display

#3 Post by ohaldi » 22 Jul 2022, 11:32

Many thanks for your help. The rules are new for me.
Can you please help me again how to start the progress bar using a GPIO input (PIR sensor) and know if the progress bar has reached 100%?

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

Re: Progress bar for display

#4 Post by Ath » 22 Jul 2022, 11:45

ohaldi wrote: 22 Jul 2022, 11:32 Many thanks for your help. The rules are new for me.
Can you please help me again how to start the progress bar using a GPIO input (PIR sensor) and know if the progress bar has reached 100%?
Reacting on the PIR sensor is rather easy, I prefer to use a Switch task for that, and suggest to use the name PIR:

Code: Select all

on PIR#state=1 do // Will be triggered when PIR detects something (most use an active-high output, change to 0 if PIR sensor has active-low output)
  AsyncEvent,Progress // Using default
endon
Responding to '100%' will require a definition of when 100% is reached, can you specify your expectations?
/Ton (PayPal.me)

User avatar
ohaldi
Normal user
Posts: 61
Joined: 31 Jan 2020, 09:10
Location: Switzerland

Re: Progress bar for display

#5 Post by ohaldi » 23 Jul 2022, 08:05

Once again, many thanks for your help.
My idea is to close a garage door automatically after a given time.
In fact, there will be two GPIO inputs. One to know if the door is already closed. Here the ESP does nothing.
Only show on the LCD that the door is closed. If the door is open, then the progress bar starts.
If a pir movement is detected on the second GPIO then the progress bar is reset.
If the progress bar reaches 100%, then on the GPIO (Relay) output, a pulse of approx. 0.5 seconds is made to start closing the door.

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

Re: Progress bar for display

#6 Post by Ath » 23 Jul 2022, 11:27

That is a clear description, thank you :)

For the Door sensor, you could add another Switch device, suggested name: Door, as a Switch allows to set a Debounce time, like 200 msec (not needed for the PIR sensor, that should provide a stable on or off signal).
The switch should probably pull the GPIO to GND when the door is open (and use an external pull-up of ~4k7 close to the ESP, because of expected wire length the internal pull up (80-100k) is too high and will cause false triggers)
To invert that door action, just set 'Inversed Logic' to checked on the Door device, and if your PIR sensor has active low, the same can be done there ;)
Code could look like this (gathered from previous posts here)

Code: Select all

on System#Boot do
  AsyncEvent,PIR#State=[PIR#State] // Let the PIR eventhandler take care of the logic
endon

on Progress do
  let 1,%eventvalue1|10% // Default n = 10
  LCD,1,1,"Timer started"
  LoopTimerSet,1,10,%v1% // Repeat timer 1 every 10 sec. for n times
endon

on Rules#Timer=1 do
  LCD,1,1,{substring:0:%eventvalue2%:****************} // Use enough * to allow all n loops to be shown
  if %eventvalue2%=%v1% // Have we reached 100%?
    AsycEvent,CloseDoor
  endif
endon

on PIR#state do // Will be triggered when PIR state changes
  if [Door#State]=0 // Door open?
    if %eventvalue1%=1 // (most pir use an active-high output, change the 'Inversed Logic' checkbox on the device for using low-active)
      TimerSet,1,0 // Stop countdown
      LCD,1,1,"Movemnt detected" // We only have 16 characters...
    else // No movement, door close procedure can start
      AsyncEvent,Progress // Using default
    endif
  endif
endon

On Door#State=1 do // Door closed
  TimerSet,1,0 // Stop any remaining timer loops, f.e. when door is closed manually
  LCD,1,1,"Door is closed"
Endon

on CloseDoor do
  LCD,1,1,"Door closing"
  LongPulse_ms,14,1,500 // Pulse relay on GPIO 14 high(1) for 500 msec
endon
NB: This is all air code, untested :D
/Ton (PayPal.me)

User avatar
ohaldi
Normal user
Posts: 61
Joined: 31 Jan 2020, 09:10
Location: Switzerland

Re: Progress bar for display

#7 Post by ohaldi » 24 Jul 2022, 10:13

Once again a big thank you for your idea. I will build a box with the components soon.

User avatar
ohaldi
Normal user
Posts: 61
Joined: 31 Jan 2020, 09:10
Location: Switzerland

Re: Progress bar for display

#8 Post by ohaldi » 29 Jul 2022, 15:40

Hello
I made a quick test board.
Everything is on a good way. I am starting to understand how the rules work. It's really good but not evident.
I also used a Display with 4x20.
Your example works well. However if the door is opened and there is no PIR movement, the progress bar does not start and at the end of the 20 characters the relay do not send a pulse.
I will also add a button to slow down the progress bar from 10s per character to 60s. To have a longer delay (about 20min)
Best regards
Otto

The last codes:

Code: Select all

// --------------------------
// Project : Garage door management with an ESP8266
// Last Change : 29.07.2022 /Ho 
// GPIO17 Door State
// GPIO02 Button lond Timer / 20min
// GPIO13 Relay Door closing pulse 
// http://192.168.90.97/control?cmd=event,CloseDoor
// --------------------------

on System#Boot do
  AsyncEvent,PIR#State=[PIR#State] // Let the PIR eventhandler take care of the logic
endon

on Progress do
// on DOOR#State=0 do
  let 1,%eventvalue1|20% // Display with 20 characters
  LCD,2,1,"Door is open"
  LoopTimerSet,1,1,%v1% // Repeat timer 1 every 10 sec. for n times
endon

on Rules#Timer=1 do
  LCD,1,1,{substring:0:%eventvalue2%:********************} // Use enough * to allow all n loops to be shown
  if %eventvalue2%=%v1% // Have we reached 100%?
    AsycEvent,CloseDoor
  endif
endon

on PIR#state do // Will be triggered when PIR state changes
  if [Door#State]=0 // Door open?
    if %eventvalue1%=1 // (most pir use an active-high output, change the 'Inversed Logic' checkbox on the device for using low-active)
      TimerSet,1,0 // Stop countdown
      LCD,1,1,"Movemnt detected" 
    else // No movement, door close procedure can start
      AsyncEvent,Progress // Using default
    endif
  endif
endon

On DOOR#State=1 do // Door closed
  lcdcmd,clear
  TimerSet,1,0 // Stop any remaining timer loops, f.e. when door is closed manually
  LCD,2,1,"Door is closed"
Endon

on CloseDoor do
  LCD,1,1,"Door closing"
  Pulse,13,1,500  // Pulse on GIPO 13 to close the Door
endon
Attachments
TestBoard.jpg
TestBoard.jpg (127.02 KiB) Viewed 2969 times

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

Re: Progress bar for display

#9 Post by Ath » 29 Jul 2022, 16:13

Ah, great, yes, I already expected that without PIR activation the close wouldn't happen, but wanted to wait your results first ;)
/Ton (PayPal.me)

User avatar
ohaldi
Normal user
Posts: 61
Joined: 31 Jan 2020, 09:10
Location: Switzerland

Re: Progress bar for display

#10 Post by ohaldi » 29 Jul 2022, 21:27

I found the following solution without PIR activation.

Code: Select all

// --------------------------
// Project : Garage door management with an ESP8266
// Last Change : 29.07.2022 /Ho 
// GPIO17 Door State
// GPIO02 Button lond Timer / 20min
// GPIO13 Relay Door closing pulse 
// http://192.168.90.97/control?cmd=event,CloseDoor
// --------------------------

on System#Boot do
  AsyncEvent,PIR#State=[PIR#State] // Let the PIR eventhandler take care of the logic
endon

on [Door#State]=0 do
   TimerSet,2,0    // Stop timer 2
   event,Progress
endon

on Progress do
  let 1,%eventvalue1|20% // Display with 20 characters
  LCD,2,1,"Door is open"
  LoopTimerSet,1,1,%v1% // Repeat timer 1 every 10 sec. for n times
endon

on Rules#Timer=1 do
  LCD,1,1,{substring:0:%eventvalue2%:********************} // Use enough * to allow all n loops to be shown
  if %eventvalue2%=%v1% // Have we reached 100%?
    lcdcmd,clear
    LCD,1,1,"Door closing"
    Pulse,13,1,500  // Pulse on GIPO 13 to close the Door
    timerset,2,10    // Timer to check it door closed after 10s
    // AsycEvent,CloseDoor
  endif
endon

On Rules#Timer=2 do // Door Timer
  if [Door#State]=0 // Door still open?
    Pulse,13,1,500  // Pulse on GIPO 13 to close the Door
    LCD,1,1,"Repeat closing door" 
    TimerSet,2,10   // Repeat timer 2 until door closed
  else
    TimerSet,2,0    // Stop timer 2
  endif
endon

on PIR#state do // Will be triggered when PIR state changes
  if [Door#State]=0 // Door open?
    if %eventvalue1%=1 // (most pir use an active-high output, change the 'Inversed Logic' checkbox on the device for using low-active)
      TimerSet,1,0 // Stop countdown
      LCD,1,1,"Movement detected" 
    else // No movement, door close procedure can start
      AsyncEvent,Progress // Using default
    endif
  endif
endon

On DOOR#State=1 do // Door closed
  lcdcmd,clear
  TimerSet,1,0 // Stop any remaining timer loops, f.e. when door is closed manually
  LCD,2,1,"Door is closed"
Endon

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

Re: Progress bar for display

#11 Post by Ath » 29 Jul 2022, 21:36

ohaldi wrote: 29 Jul 2022, 21:27 I found the following solution without PIR activation.

Code: Select all

// --------------------------
on [Door#State]=0 do
That needs the square braces removed or it won't work as intended
/Ton (PayPal.me)

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 18 guests