Offline
Jr. Member
Karma: 0
Posts: 92
|
 |
« on: December 23, 2012, 09:44:19 am » |
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  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?
|
|
|
|
|
Logged
|
|
|
|
|
|
|
Offline
Edison Member
Karma: 114
Posts: 2205
|
 |
« Reply #2 on: December 23, 2012, 12:11:12 pm » |
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. But there are just 2 interrupts on the Arduino? there are numerous interrupts. 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. But that would mean that "digitalRead INPUT" is useless? It is useless only in the hands of useless programmers.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 92
|
 |
« Reply #3 on: December 23, 2012, 01:50:11 pm » |
You can buy a MEGA I have two Mega but they also have just 6 interrupt pins. 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.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Edison Member
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
|
 |
« Reply #4 on: December 23, 2012, 02:17:20 pm » |
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... 
|
|
|
|
|
Logged
|
|
|
|
|
Netherlands
Offline
Tesla Member
Karma: 86
Posts: 9360
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #5 on: December 23, 2012, 03:04:58 pm » |
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 -
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 92
|
 |
« Reply #6 on: December 23, 2012, 03:12:36 pm » |
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 
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Edison Member
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
|
 |
« Reply #7 on: December 23, 2012, 03:29:40 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Valencia, Spain
Offline
Edison Member
Karma: 65
Posts: 2227
|
 |
« Reply #8 on: December 23, 2012, 03:33:15 pm » |
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...
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 92
|
 |
« Reply #9 on: December 23, 2012, 06:04:17 pm » |
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  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: 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.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Edison Member
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
|
 |
« Reply #10 on: December 23, 2012, 06:58:04 pm » |
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)  (edit: RTOSs, obviously  )
|
|
|
|
« Last Edit: December 23, 2012, 08:10:44 pm by tuxduino »
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 92
|
 |
« Reply #11 on: December 23, 2012, 07:11:02 pm » |
Go where you feel the fun is (tm)  I better don't comment that *lol
|
|
|
|
|
Logged
|
|
|
|
|
Valencia, Spain
Offline
Edison Member
Karma: 65
Posts: 2227
|
 |
« Reply #12 on: December 24, 2012, 05:24:47 am » |
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...
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 92
|
 |
« Reply #13 on: December 24, 2012, 05:38:18 am » |
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! 
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Edison Member
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
|
 |
« Reply #14 on: December 24, 2012, 08:06:26 am » |
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 ? 
|
|
|
|
|
Logged
|
|
|
|
|
|