Would it be possible to use an interrupt pin on the arduino uno as a trigger for multiple buttons? That way when any of the buttons is pressed the interrupt is triggered, and the microcontroller could then see which of the pins has been pushed. I would attach an interrupt to each button individually but there are only two available on this arduino. I will attach a circuit diagram for how I was thinking to set it up.
If you are short of pins, you could even use a single analogue pin to check on four buttons. Just use four voltage dividers that put out say, 0.8, 0.6, 0.4, and 0.2 of power supply voltage, and use four NO pushbuttons to direct these voltages to an analogue pin.
You could use one resistor to ground hardwired to the pin to keep it at 0 v. when the buttons are all open. Then use a resistor attached to power supply voltage on the other side of each button. When you close any button, the voltage becomes a function of the common resistor (to ground), and the one attached only to that button.
By varying the four resistors to the buttons, you get different voltages for each button. The only drawback is that instead of the code automatically going to service an interrupt, you have to check the pin each time through the loop.
You can use pin change interrupts on every pin. But you only get one interrupt per 'port' so you then read the inputs to work out which pin changed, which is very much like your scheme.
Are these buttons pressed by a person? Do you need microsecond accuracy on the timing? Interrupts are probably not the correct solution for your problem.
A poster with a single post so far, talking about interrupts, suggests he has no idea whatsoever what interrupts are for.
Pushbuttons are served by "polling".
And someone who shows the buttons connected to the 5 V supply and using pull-downs has clearly been reading the poorest of tutorials or "instructables". Unfortunately, this is where these ideas about "interrupts" usually come from - the two unfortunate misunderstandings go hand in hand.
OP: We are here to help. You exhibit the "XY problem". You are asking how to do something quite inappropriate which you imagine might be the way to do it instead of explaining what your actual purpose is and asking how properly to go about it.
There is probably a better way to hook up the buttons
Interrupts are probably not the best solution to this problem
Further explanation of what I would like to achieve:
The Arduino Uno's main purpose is to read some sensors, temperature mostly, and then drive a stepper motor through use of a shield and then display information to a 20x4 LCD. The reason I was reluctant to just continually poll the pins every loop for a change in state is, as a programmer, that seems like a huge waste of system resources when the buttons are rarely going to be used.
Can someone tell me what is wrong with hooking up buttons to the 5V supply on the Arduino?
Can someone tell me what is wrong with hooking up buttons to the 5V supply on the Arduino?
You need an external resistor to ground, and you have 5v available to create shorts distributed around your board.
It is more simple and safer to use INPUT_PULLUP mode instead. The switch is connected between the input and ground. Logic is reversed. When a NO button is pressed, the input reads LOW.
Computers exist to serve us. If the Arduino checks an input 10,000 times per second for 5 years until someone pushes the button, then that seems "efficient" to me.
A PC with 1% CPU usage is actually spending 99% of its time waiting for you. The processor clock still runs at the same speed. It's still using up the same number of processor cycles, it just calls those cycles "idle."
The reason I was reluctant to just continually poll the pins every loop for a change in state is, as a programmer, that seems like a huge waste of system resources when the buttons are rarely going to be used.
What else are you going to do with all the CPU time?
This really just goes to show that a 16MHz is far to fast for most jobs here.