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 ...
starship15's user avatar
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]);
Ignacio Vazquez-Abrams's user avatar
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 ...
Marco's user avatar
  • 186
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 ...
gilhad's user avatar
  • 1,410
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 "...
JRobert's user avatar
  • 15.1k
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 ...
tlongeri's user avatar
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 ...
Jot's user avatar
  • 3,216
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 ...
computercarguy's user avatar
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 ...
Michel Keijzers's user avatar
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 ...
Majenko's user avatar
  • 105k
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 ...
Edgar Bonet's user avatar
  • 42.2k
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 ...
MikeDB's user avatar
  • 131
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 ...
Feu's user avatar
  • 121
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 ...
gencer's user avatar
  • 21
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 ...
Majenko's user avatar
  • 105k
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 ...
Lou Geezer's user avatar
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 ...
HiWay's user avatar
  • 109
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 ...
James Waldby - jwpat7's user avatar
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 ...
Nick Gammon's user avatar
  • 37.9k
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 ...
Dave Tweed's user avatar
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 ...
Duncan C's user avatar
  • 5,652
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 ...
JRobert's user avatar
  • 15.1k
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 (...
DataFiddler's user avatar
  • 1,045
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 ...
Kerbolosh's user avatar
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 ...
6v6gt's user avatar
  • 1,018
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()){ ...
Nick Gammon's user avatar
  • 37.9k
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.
atland's user avatar
  • 179
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 ...
dannyf's user avatar
  • 2,760
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 ...
Jot's user avatar
  • 3,216
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 ...
amorimph's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible