How can one register an interrupt on an analog pin.
I have an IR reciever set up on analog pin 0 and I want to an interrupt whenever it reads LOW.
I did a bit of looking and apparently a comparator is used, but I have no clue on how to register the interrupt with it… >.< … this one below.
void setup() {
ACSR =
(0<<ACD) | // Analog Comparator: Enabled
(0<<ACBG) | // Analog Comparator Bandgap Select: AIN0 is applied to the positive input
(0<<ACO) | // Analog Comparator Output: Off
(1<<ACI) | // Analog Comparator Interrupt Flag: Clear Pending Interrupt
(1<<ACIE) | // Analog Comparator Interrupt: Enabled
(0<<ACIC) | // Analog Comparator Input Capture: Disabled
(1<<ACIS1) | (1<ACIS0); // Analog Comparator Interrupt Mode: Comparator Interrupt on Rising Output Edge
}
ISR(ANALOG_COMP_vect)
{
}
I do apologise if my question makes no sense at all 3:
EDIT:
Is this a viable replacement???
int reading;
boolean go = False;
volatile int npulses = 0;
volatile unsigned long lasttime = 0;
volatile int distance = 0;
void countPulse() {
//execute pulse counting code
}
void setup() {
pinMode(0, INPUT);
Serial.begin(9600);
}
void loop() {
reading = analogRead(0);
if (reading == 0) { // For the IR reciever the value drops to 0/LOW when recieving a signal
go = True;
}
if (go == True) {
countPulse();
go = False;
}
}