Arduino Uno Interrupt with 2 switches

Hello all,
Most simply put, I am working on a project that requires that I be able to add or remove time to a running timer. I attached a momentary push button switch to pin 2 so that when it is pushed 5 volts are applied and when it is not pushed the pin is pulled to ground via a 10k resistor, using this code:

attachInterrupt(0, ChangeTime, RISING); // Setup interrupt for adding time

void ChangeTime()
{
static unsigned long last_interrupt_time = 0;
unsigned long interrupt_time = millis();
// If interrupts come faster than 200ms, assume it's a bounce and ignore
if (interrupt_time - last_interrupt_time > 200)
{ Time += 30; }
last_interrupt_time = interrupt_time;
}

This code is working properly, however, I am wondering if there is any way to use one interrupt pin to respond to two different conditions.
I would like to have a physical button to increase the timer, and another physical button to decrease the timer, but only use one of my two available interrupt pins (I need the second pin for another sensor)

I attempted to do this with a circuit where, if no buttons were pushed, the pin saw 2.5V. pushing one button applies 5v, and pushing the other applies 0v, using the following code:

attachInterrupt(0, ChangeTime, CHANGE); // Setup interrupt for adding time

void ChangeTime()
{
static unsigned long last_interrupt_time = 0;
unsigned long interrupt_time = millis();
// If interrupts come faster than 200ms, assume it's a bounce and ignore
if (interrupt_time - last_interrupt_time > 200)
if (digitalRead(2) == HIGH)
{ Time += 30; } // increase time
if (digitalRead(2) == LOW)
{ Time -= 30; } // decrease time
last_interrupt_time = interrupt_time;
}

This only seemed to work when I alternated HIGH and LOW values buy pushing the increase time button followed by the decrease time button. If I pushed increase time twice it did not register (I assume "CHANGE" only looks for a full 5v change in the input voltage?)

Is there any way I can alter my code to get this to work? (make it so the program looks for a 2.5 volt change)
Or perhaps a hardware solution?

Thanks!

Depending on exactly what it is you're trying to do,an interrupt may not even be necessary.
Can you expand your problem, please?

Well the main loop is monitoring temperatures and writing to a display every second, and I would rather not clutter it with code polling an input pin during every loop. Issues also arise when I try to retrieve a temperature from my sensor too quickly so the timing is rather fixed.

I certainly could find a way to make it work without an interrupt, but using an interrupt would simplify my main loop if there is a way to do what I described above.

Well the main loop is monitoring temperatures and writing to a display every second

Every second is not interrupt territory.
Interrupts are for conditions that are unlikely to last beyond the next instruction (1 / 16 000 000 th of a second)

using an interrupt would simplify my main loop

Interrupts rarely simplify anything.

Well, my question isn't about whether or not I need an interrupt, its how to use one. Id rather not attempt to try to explain what the rest of my program is doing and why I'd like to use an interrupt.

I can think of one hardware solution in which pushing either button applies 5v to the interrupt pin to trip the interrupt, and either 5v or 0v to another pin (pin 5 for example), which determines whether to add or subtract time.

Interrupts rarely simplify anything.

Add an or or nor gate, connect the or output to pin2 and the button pins to 2 free pins and the or inputs. Receive the interrupt, read the pins. (I never tried such a design). that might reflect your specs hypothetical.

There is nothing you can in the program to make a digital input to distnguish three values. Either it is LOW or it is HIGH, your explanation seems to be asking for this.

Your 2nd code seems to do the reasonable thing - when the interrupt is triggered by a change on pin0 (bad choice, BTW, they are used/interfere with the serial stuff) it uses the value of pin2 to decide if we go or down.

So I suspect your circuit if it goes 2.5 - 5 - 2.5 - 5 that is not counted as a change by the pin0 input (any voltage higher than about 1 V is read as HIGH, according to the specs). It is not clear from you explanation which pin your trying to read "BetweenLOW&HIGH", but it wont work either way.

Excellent, this is the sort of response I was looking for.

also, attachInterrupt uses 0 for physical pin 2, and 1 for physical pin 3.
So attachInterrupt(0,...) refers to pin 2. (I learned the hard way not to mess with pin 0 for the reason you stated haha)

I'm going to try using an or gate, that should work perfectly. Im hoping to use a rotary encoder in the future but this should work for now.
Thanks!

AWOL:

Interrupts are for conditions that are unlikely to last beyond the next instruction (1 / 16 000 000 th of a second)

Or... Interrupts are for processes that take a relatively long time, as compared to processor speed. For example, an I/O operation to a disk drive. Mechanical devices are orders of magnitude slower that the processor; we can get more work done if we don't have to stop and wait for them. The processor can start the I/O operation, then continue to process other work. When the I/O is complete, the disk drive signals the processor with an interrupt so that it can process the result of the I/O operation.

And... Interrupts are for high-priority processes. Responding to input (buttons) is more than likely a higher priority than running the display. In fact, running the display is probably one of the lower priorities. At least that approach works well for me.

I am working with a VFD display, and the frame signal interrupt (like a vertical blank) is VERY useful.

captaincat54:
I am wondering if there is any way to use one interrupt pin to respond to two different conditions.

This question came up earlier today:

http://arduino.cc/forum/index.php/topic,56605.0.html

Some of the solutions there should help.

Also, I recently did a post about using 16-bit port expanders, which gives you an extra 16 ports, any of which can generate an interrupt. So that would give you heaps of digital lines with interrupts. You don’t get 16 different interrupts, but you get one and in the interrupt routine you can work out which pin actually caused it.

http://www.gammon.com.au/forum/?id=10945