7
votes
Accepted
Debouncing a button with interrupt
So, I grabbed a Mega and several pushbutton switches (one of which turned out to be a push-on, push-off, much to my bemusement), and ginned up a small Arduino program to illustrate an interrupt-driven ...
5
votes
Instead of 1 and 0, make display say On or Off
Put the strings to display in an array, and output them instead.
char const * const stateDisplay[] = {"Off", "On"};
...
lcd.print(stateDisplay[state]);
4
votes
Accepted
Why doesn't this debounce function work?
This probably won't answer your question completely, but here are some notes from me:
buttonState = current ; //read value again now that bouncing is over
This won't read the value again, it just ...
4
votes
Accepted
Interrupts: use of the "volatile" keyword with a structure pointer for button debounce
I think, that the problem is in ideb_read, which expects "a pointer to (non-volatile) structure" and so it does not care about re-reading ideb->output if it can it optimize out somehow (say putting ...
4
votes
Interrupts: use of the "volatile" keyword with a structure pointer for button debounce
Getting pointer declarations right can be anything but obvious, especially where const and volatile are concerned (which are syntactically equivalent). Your problem stemmed from the confusion between "...
4
votes
Accepted
Code test the duration press of the button
Why did the timers stop working?
The main issue seems to be that freeze_timer and btn_timer are of type unsigned int, while millis, as stated in its documentation, returns an unsigned long.
As you ...
3
votes
Accepted
Problem with Dual Safety Switches Initiating Timed Relay
The Arduino has a loop function, that runs over and over again.
The Arduino has a millis function for the time.
Those two combine beautifully with a state machine.
Once I made a function that ...
3
votes
Why can I measure two pins simultaneously?
https://github.com/thomasfredericks/Bounce2/wiki
I'm not familiar with the Bounce(2) library, but looking at the above site, it looks like "fell" is more of an "instant" thing, where it isn't ...
3
votes
Accepted
Why can I measure two pins simultaneously?
You can test it easily by calling the function twice directly after each other. If the first time a true is returned and the second time a false, the state is internally reset.
But probably because ...
3
votes
Accepted
How to simulate delay() to debounce mechanical button using millis()?
To better understand how you can do this it is good to understand first just what goes on when a button bounces.
It is, literally, bouncing - just like a ball when you drop it. Due to the fact that ...
3
votes
Accepted
minimal code for multiple buttons de-bouncing
Yes, your code should work as the most basic debouncing, although the
debouncing time may be a little bit short. Note however that, in many
instances, one would like to have a little more that the ...
3
votes
Will a simple RC filter work with my mechanical rotary encoder, or do I need a Schmitt trigger?
Having just chased a problem using a software based debounce for several days, what I'll add is that for the encoders I was using (green no-name Chinese ones), if you put 10mA though the contacts then ...
2
votes
Good button debouncing/stateChange library
I'm on this subject right now and I'll use this to note my findings.
I found many libs on this, and this is my wishlist:
support many buttons
support toggles or switches
support debouncing and maybe ...
2
votes
Good button debouncing/stateChange library
You can use my library
https://github.com/anlgncr/Buttons
This library lets you use buttons as many as you wish with only one instance of class.
You can also call a function when button is pushed ...
2
votes
Accepted
Instead of 1 and 0, make display say On or Off
Another option: use the "inline" if construct:
lcd.print(state ? F("On") : F("Off"));
The format is:
<if comparison> ? <true result> : <false result>
Note the use of F(...) to ...
2
votes
How to simulate delay() to debounce mechanical button using millis()?
Actually, Majenko's diagram assumes the interplay of the pullup resistor forces the line back to a HIGH position (as quickly as the internal transistors can overpower the drop from the switch). If ...
2
votes
Help Improving Debouncing
I have used and know of many others who use the Bounce2 Library to provide an easy way to debounce the switch without using any delays so the user wouldn't have to pause between presses. Behind the ...
2
votes
Help Improving Debouncing
Many of the lines shown in the program box are superfluous – totally redundant and unnecessary. I suggest that you revise it [see (a)-(d) below], then replace all the stuff in the program box with ...
2
votes
Interruption triggered twice when set to FALLING
but sometimes when releasing the button the interruption also fires
Yes, well when you release the button it may also bounce. In other words OFF/ON/OFF so that will count as a press. A capacitor over ...
2
votes
Why doesn't this debounce function work?
"It worked perfectly" is probably an overstatement. Yes, you saw the LED change when you pressed the button, but that doesn't mean it was getting debounced.
The problem is that you are trying to use ...
2
votes
Will a simple RC filter work with my mechanical rotary encoder, or do I need a Schmitt trigger?
The answer seems to be no. I added the RC filter suggested by the manufacturer and the results still jump around (The values sometimes increase by several steps at once, or decrease even when turning ...
2
votes
Accepted
Measure revolutions per second with reed switch
It sounds like occasional "misses". Possible causes include:
the magnet passing far enough from the reed switch to "only just" trigger it [narrow the gap.];
the magnet's passage being too short for ...
2
votes
Accepted
Understanding Debounce code
loop() does not need any time and repeats permanently.
lastButtonState is reading from previous loop run.
As long as the button bounces, lastDebounceTime is updated.
Only when the button has settled (...
2
votes
Accepted
Basic hardware debouncing
You did not change the lastbutton, but you compared it to HIGH. Change your code to the one below.
You can more easily avoid such mistakes, if you put spaces around operators.
//sp is switchpin, lp is ...
2
votes
Accepted
Interrupt on button press + debouncing
Here is a non-blocking debouncing solution which is suitable also for electrically noisy environments. For example where there are long wires to the buttons which could pick up spurious signals. In ...
1
vote
Accepted
Debouncing Multiple Buttons
Your first problem is here:
char ReadKeypad(){
if(button1.isPressed() && !button2.isPressed()){
return 'D';
}
else if(button2.isPressed() && !button1.isPressed()){
...
1
vote
Why can I measure two pins simultaneously?
Maybe I missed something but the branch doesn't execute because
button0.fell() & button1.fell()
should be
button0.fell() && button1.fell()
the else if clause also never executes.
1
vote
Why can I measure two pins simultaneously?
I'm getting some strange results:
your code doesn't really measure the two pins "simultaneously". instead, it measure the two pins sufficiently fast and it appears to be simultaneously.
use input ...
1
vote
Accepted
State Machine Logic problem with added states monitoring safety switches
Intro
You did not get any answers, because someone has to read the whole sketch and you have not explained which problem you want to solve with the two extra states and you did not fully explain what ...
1
vote
Problem with Dual Safety Switches Initiating Timed Relay
From what I understood, this is what you're trying to do:
Turn a relay on as long as both buttons are pushed for 'pushWindowTime' milliseconds;
Keep the relay on for 'relayOnTime' milliseconds, or ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
debounce × 48button × 22
arduino-uno × 10
interrupt × 9
programming × 6
led × 6
millis × 5
serial × 4
c++ × 4
code-review × 4
rotary-encoder × 4
lcd × 3
teensy × 3
servo × 2
library × 2
sketch × 2
switch × 2
isr × 2
esp8266 × 1
arduino-mega × 1
arduino-nano × 1
nodemcu × 1
usb × 1
atmega328 × 1
timers × 1