I'm a bit confused about how a switch setup is working. The switch is build into a rotary encoder so its a momentary switch. I have GPIO set up as "input-pullup" and in the device page for the switch I have the switch type as "push button active low". Setting for longpress is not checked.
When I press the switch quickly the state toggles from 0 to 1 or vise versa and stays that way.
When I press the switch for a couple seconds it toggles from one state to another and then back to where it was.
In my mind it should always be at state "1" when the switch is at rest and at state "0" whenever the switch is pressed on.
Change switch to "push button active high" and it gets more interesting... GPIO setting the same.
Quick press the switch and it toggles from 0 to 1.
Long press (or hold) the switch and no state change until you let go of the switch and it then toggles from 0 to 1 just like a short press.
Is this expected behavior? Seems very counter-intuitive to me.
Question about switch function.
Moderators: grovkillen, Stuntteam, TD-er, enesbcs
- budman1758
- Normal user
- Posts: 301
- Joined: 15 Apr 2017, 05:13
- Location: Riverside CA USA
Question about switch function.
"The glass is twice as big as it needs to be".
Re: Question about switch function.
"Normal" switch mode is that its output state reflects the GPIO state. (or inverted if "invert" was checked)
The other modes like "active on low" or "active on high" are toggle modes.
Meaning when you pull the GPIO low (pull to GND) you switch the state. (or pull to high, depending on the mode)
If you have some simple push button which is located on a lot of boards, those will return to the default state when you no longer press them.
So those are the best candidates for the "toggle" modes, as a single press just switches the state.
The "normal" switch mode is more likely to be used on some toggle switch of something to record a state that's likely to be in a specific state for longer time.
For example a level switch or a flip switch to turn on/off something, or detecting whether something is on/off (measuring the voltage as a binary value)
The other modes like "active on low" or "active on high" are toggle modes.
Meaning when you pull the GPIO low (pull to GND) you switch the state. (or pull to high, depending on the mode)
If you have some simple push button which is located on a lot of boards, those will return to the default state when you no longer press them.
So those are the best candidates for the "toggle" modes, as a single press just switches the state.
The "normal" switch mode is more likely to be used on some toggle switch of something to record a state that's likely to be in a specific state for longer time.
For example a level switch or a flip switch to turn on/off something, or detecting whether something is on/off (measuring the voltage as a binary value)
Re: Question about switch function.
If there are some unexpected effect between quick and slow methods, you can try to change debounce time.budman1758 wrote: ↑04 Apr 2021, 20:00 When I press the switch quickly the state toggles from 0 to 1 or vise versa and stays that way.
When I press the switch for a couple seconds it toggles from one state to another and then back to where it was.
It is the normal type, what you described here, with inverted gpio values.budman1758 wrote: ↑04 Apr 2021, 20:00 In my mind it should always be at state "1" when the switch is at rest and at state "0" whenever the switch is pressed on.
Re: Question about switch function.
Premise: gpio 12 is assigned as input switch, pushbutton active on high. Same gpio/pushbutton is used to wakeup LCD, as "Display button:". Short press wake up the LCD.Now we want to use longpress function of same gpio,something like that: 1st longpress enable task 1, 2nd longpress disable task 1, use longpress to toggle something...It's that possible?
Re: Question about switch function.
with a dedicated rule and a dummy value which holds the counter of longpress events, i guess that it is possible.bonti69 wrote: ↑06 May 2021, 18:32 Premise: gpio 12 is assigned as input switch, pushbutton active on high. Same gpio/pushbutton is used to wakeup LCD, as "Display button:". Short press wake up the LCD.Now we want to use longpress function of same gpio,something like that: 1st longpress enable task 1, 2nd longpress disable task 1, use longpress to toggle something...It's that possible?
Who is online
Users browsing this forum: No registered users and 0 guests