Go Down

Topic: Buttons, interrupts and de-bouncing (Read 2411 times) previous topic - next topic

MrGlasspoole

Hi,

i just figured out that switching is not as easy as it seams.
Yes i recognized that sometimes the reaction on my buttons are poor - but i always
thought my buttons are cheap or i did not push enough XD

So now i was reading about de-bouncing and seams like that the Schmitt-Trigger solution is the
best choice. But when i was reading i stumbled over interrupts.
So attaching my buttons to the digital pins is not the best choice cause you need to
read the pins in a loop all the time to see if there is a change.

But there are just 2 interrupts on the Arduino?
So what to to if i want (for example) to switch 24 devices with 24 switches?

That also brings me to the question: every time i have something that only has a
low and high as input would better go to an interrupt (also if its maybe a optocoupler you read just to see on and off)?
But that would mean that "digitalRead INPUT" is useless?

robtillaart

Quote
But there are just 2 interrupts on the Arduino?

There is also - http://arduino.cc/forum/index.php?topic=87195.0 -

Quote
So what to to if i want (for example) to switch 24 devices with 24 switches?

You can buy a MEGA or a shield like - http://macetech.com/store/index.php?main_page=product_info&products_id=23 -
lots of shields on shieldlist.org

also check - http://playground.arduino.cc//Code/Bounce - for debouncing code
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

dhenry

Quote
So now i was reading about de-bouncing and seams like that the Schmitt-Trigger solution is the
best choice.


Whether something is best depends on the application.

Quote
But there are just 2 interrupts on the Arduino?


there are numerous interrupts.

Quote
So what to to if i want (for example) to switch 24 devices with 24 switches?


Switching 24 devices is not the same as reading 24 switches.


Quote
But that would mean that "digitalRead INPUT" is useless?


It is useless only in the hands of useless programmers.

MrGlasspoole


You can buy a MEGA
I have two Mega but they also have just 6 interrupt pins.
Quote from: dhenry
It is useless only in the hands of useless programmers.
Sound like a sentences from somebody who was born and did
know programming and never had to start and learn.

tuxduino

Quote
I have two Mega but they also have just 6 interrupt pins.


You don't have to tie each interrupt to just one button. You can for example have a row of buttons all trigger the same interrupt, and have the ISR figure out which button(s) it was that was pressed by immediately reading each button status.
Off of top of my head I don't know how this would be wired/coded in exact details, but I recall something similar is implemented in chips like PCF8574: it triggers an int, then the ISR asks the chip its pin status (8 pins => 1 byte, i2c => very fast). Have a sample sketch running on a breadboard with a UNO. 2 arduino pins, 8 buttons. Not bad... :)

robtillaart

Quote
I have two Mega but they also have just 6 interrupt pins.

No, you can have an interrupt for any pin just as tuxduino describes.

There is a library for it. Read this thread - http://arduino.cc/forum/index.php?topic=87195.0 -
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

MrGlasspoole

I will read i later. But just from overflying it i thought its just for the ATmega328p.

So does it make sense to always use interrupts for switching state instead of using
just digital IN and look at it all the time in a loop?
Please correct me if my logical thinking is not right :|

tuxduino

Polling is perfectly usable to manage buttons, provided you read the pin status at least once in 20 to 50 ms. That means banning delay() and switching to state-based programming.

fungus

I think the real problem is using interrupts to detect button presses.

It sounds neat/cool/whatever but it's not really a good idea in practice...
No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

MrGlasspoole

Cool? Hm, i think nobody ever will ask: "hey how does this button work? do you use interrupts?"
If i build a egg timer for my 60 years old Mother. She never ever will look at the code or ask.
An Arduino for a egg timer *looool
But who knows. When Skynet comes alive and all machines communicate, maybe the egg timer is
in charge for the timing of the Terminator sorties :D

I just want to figure out whats the right way to do it. If you need to check the inputs
in the loops then the Atmega uses energy you maybe need for other stuff.
I always think that stuff needs to be build that it uses the least energy.
The other thing i read at Jeremy's (Blum) blog is:
Quote
Interrupts allow you run a program, while still being able to react to asynchronous input from the outside world.

So you can do stuff at the same time.

tuxduino

#10
Dec 24, 2012, 12:58 am Last Edit: Dec 24, 2012, 02:10 am by tuxduino Reason: 1
Yes, ints are cool. So i multitasking. ROTSs are even cooler. Superloops are a bit less cool.  But they're easier to grasp, IMHO.

That said, use whatever technique you feel more inclined to learn. Go where you feel the fun is (tm) :D


(edit: RTOSs, obviously :P )

MrGlasspoole


Go where you feel the fun is (tm) :D
I better don't comment that *lol

fungus


Cool? Hm, i think nobody ever will ask: "hey how does this button work? do you use interrupts?"
If i build a egg timer for my 60 years old Mother. She never ever will look at the code or ask.


I mean the person who writes the program...
No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

MrGlasspoole


I mean the person who writes the program...
So we need shirts now for the cool people with the print on them: I am a interrupter!
XD

tuxduino

Come on, let's be serious. The t-shirt should read "I'm an ISR writer". Now how about that for making people go "wow" when you pass by ? :D

Go Up