The following sketch will run on both the Arduino Micro and the Uno. However the behaviour is not the same.
int sensorValue = 0;
//let's set up the hardware
void setup() {
Serial.begin(9600);
//analogComparator.setOn(AIN0, A0);
//initialize the analog comparator (AC)
ACSR &= ~(1<<ACIE); //disable interrupts on AC
ACSR &= ~(1<<ACD); //switch on the AC
ACSR &= ~(1<<ACBG); //set pin AIN0
ADCSRA &= ~(1<<ADEN);
ADMUX &= ~31; //reset the first 5 bits
ADMUX |= 0; //choose the ADC channel (0..NUM_ANALOG_INPUTS-1)
ADCSRB |= (1<<ACME);
}
//main loop
void loop() {
if (ACSR & _BV(ACO))
{
Serial.println("high");
}
else
{
Serial.println("low ");
}
//sensorValue = analogRead(A0);
delay(500);
}
To get the same behaviour the line
containing
//sensorValue = analogRead(A0);
needs to be uncommented for the Arduino Micro to allow the comparator output to be read.
I have two adjustable voltage sources connected to both boards, one to AIN0 the other to A0.
If AIN0 is set to about 2.5V and A0 is adjusted around that voltage I would expected to see "High" and "Low" as alternating outputs, depending on the timing of the voltage changes.
With the UNO no problem
With the Micro no change, unless the identified line is uncommented.