How to program a pulse if input goes to high and same pulse when input goes low

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
BartSr
Normal user
Posts: 115
Joined: 27 Sep 2019, 17:45

How to program a pulse if input goes to high and same pulse when input goes low

#1 Post by BartSr » 15 Nov 2021, 18:23

In dutch we call this a veegcontact.
Google translate says passing contact.
Can we have a pulse on output if an input goes high and then, once input goes low a pulse again?
Thanks for your help.
Bart

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

Re: How to program a pulse if input goes to high and same pulse when input goes low

#2 Post by TD-er » 15 Nov 2021, 23:08

So you want an event on the "rising" and "falling" edge of the pulse?

This can be done using the switch plugin and some small rules.

The Switch should be set to "Normal Switch", as it will send an event on every state change.
You can even add some filtering if you like to suppress any bouncing ("anti-dender schakeling" in Dutch :) )

As an example, you create a task with the "Switch input" plugin and name it "veeg"

With the default variable name "State" you will get 2 events:
veeg#State=0
veeg#State=1

So in the rules you can act on the veeg#State event and keep track of the state using a variable.

Code: Select all

on veeg#state do
  if %eventvalue1% = 0
    // Do stuff when the veegcontact is entered
  
  else
    // Do stuff when the veegcontact is exited
  
  endif
endon

User avatar
ThomasB
Normal user
Posts: 1064
Joined: 17 Jun 2018, 20:41
Location: USA

Re: How to program a pulse if input goes to high and same pulse when input goes low

#3 Post by ThomasB » 16 Nov 2021, 02:19

And for those sitting in the peanut gallery, this use case can use a simpler event rule:

Code: Select all

on veeg#state do  // Contact has opened or closed.
                  // Do stuff here. Will be the same for open or close.
endon
But when the rule must act differently (open rule actions different from close rule actions) then follow the example provided by @TD-er.

- Thomas

BartSr
Normal user
Posts: 115
Joined: 27 Sep 2019, 17:45

Re: How to program a pulse if input goes to high and same pulse when input goes low

#4 Post by BartSr » 17 Nov 2021, 09:58

Thanks for your help.
I see how to act once an inputstate changes but how to hook this onto an output in way that that output is activated for e.g. 500 MiliSeconds (pulse)?

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

Re: How to program a pulse if input goes to high and same pulse when input goes low

#5 Post by TD-er » 17 Nov 2021, 10:05

This can be done in 2 ways:
Either set the debounce to 500 msec, so everything less will be ignored.
Or enable to send a longpress event

For the longpress event, depending on your selection, the %eventvalue1% will be either 10 or 11 when a longpress is detected.

BartSr
Normal user
Posts: 115
Joined: 27 Sep 2019, 17:45

Re: How to program a pulse if input goes to high and same pulse when input goes low

#6 Post by BartSr » 17 Nov 2021, 11:00

TD-er,

Once again thanks for reply. But IMHO using the debounce-time makes no sense as it should be the otheway around. Once the output has been activated by change of an inputstate the output must be activated immediately for just 0,5 sec. By using debounce the output is just delayed as log as debounce-time is set. If input has been de-activated same must happen. Output must be activated for 0,5 sec.
Or did I understood the 'debounce-time' wrong?

Thanks,
-Bart

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

Re: How to program a pulse if input goes to high and same pulse when input goes low

#7 Post by TD-er » 17 Nov 2021, 13:46

Nope, you've got it right.
So that leaves the "long press" feature.
N.B. you can combine both, like 50 msec for the debounce and 500 msec for the long press.
Just check for the %eventvalue1% value to see which event you're handling (there may be multiple)

User avatar
ThomasB
Normal user
Posts: 1064
Joined: 17 Jun 2018, 20:41
Location: USA

Re: How to program a pulse if input goes to high and same pulse when input goes low

#8 Post by ThomasB » 17 Nov 2021, 18:58

I'm a bit confused. The questions seem to concern the output pulse, but the discussion is centered on the input trigger. Although both are involved in your application, those are two different actions.

I seems that you want to send a 500mS pulse on an output pin when some other input pin changes state. If that is the case, then the event rule discussed earlier would simply call LongPulse_ms.

The LongPulse_ms command is described in the ESPEasy Command docs. https://espeasy.readthedocs.io/en/lates ... mmand.html

Command excerpt shown below:

Code: Select all

LongPulse_ms,<GPIO>,<state>,<duration>
GPIO: 0 … 16
State: 1/0
Duration: 10 … 15000 msec
To send a *long* pulse to a certain pin. A LongPulse_mS is the same as the regular LongPulse. 
The only difference is the time base in milliseconds rather than in seconds.
Let's say you want to generate an active high pulse on GPIO14 for 500mS when an Switch Input named "veeg#state" is opened or closed. Here is an example rule (you would need to change it to match your pin definitions).

Code: Select all

on veeg#state do  // Contact has opened or closed.
  LongPulse_ms,14,1,500 // Send pulse on Open or Close.
endon
- Thomas

Post Reply

Who is online

Users browsing this forum: No registered users and 26 guests