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?
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...
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
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.
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.
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.
Ok, more confused
I found this from Ladyada and she writes:
"To change the pins or number of buttons, just put them in the array called “buttons” and the rest of the code will automatically adjust."
The second sketch uses interrupts. But she is using analog inputs and how can i just ad buttons if i can't just
use every input pin as interrupt??