I've had a read around this subject and want to confirm that my understanding is correct, I am using an Arduino board that has an ATMega 1280 chip.

As I understand it, the Analog Comparator can be set up to trigger an interrupt when the voltage on the A1 pin exceeds the voltage on the A0 pin. So presumably if I connect a potentiometer to A0 can set the trigger voltage to a suitable threshold (I'm looking at something that swings from around 2.5v to 1v)?

Can I set it up to trigger an interrupt if the voltage at A1 falls below A0?

The analog comparator is all documented in Chapter 23 of the datasheet/manual. You will want to download the big version of the datasheet to get detailed information. I could set it all up for you, but you wouldn't learn anything. Start by looking at the datasheet and then come back with your questions after doing some research of your own. I'll be happy to help then.

I don't of any library that you can use to make it simpler, so you'll pretty much have to code things the same way that you'd do it in assembler. I will make a test program today for my Uno that uses the analog comparator.

That's what I meant, I didn't mean I was going to write him an actual assembly language program. I was referring to the fact that the OP will have to refer to register and bit names and positions to set it up. Just like in your example. Libraries generally eliminate (or at least abstract) that to insulate users from having to know the gory details and also to make programs more portable.

Compares voltage sensed at pins 6 (AIN0) and 7 (AIN1) which are the analog inputs into the comparator. AIN0 is the positve input and AIN1 is the negative input to the comparator. Once the voltage on AIN0(+) rises above the voltage sensed at AIN1(-), the comparator output becomes high and triggers the interrupt to run. The interrupt routine toggles the LED connected to Pin 13. The ACO flag is tested in the loop() and Pin 9 is set to match.

The circuit: * Simple voltage divider made from two 10k resistors with the midpoint connected to AIN1(Pin 7 -) The end points of the resistors connect to +5V and ground

* Varying input voltage that is normally below the set point of the divider. I used a CDS photocell above a 10k resistor configured as a voltage divider. The photocell connects to +5 and the 10k resistor, the other resistor leg connects to ground.

* On board LED connected to Pin 13

* Another LED connected to Pin 9 that reflects the status of the comparator output.