darrob:
https://www.arduino.cc/en/Hacking/PinMapping32u4This (and the associated links) make for some interesting reading as well
That clears up a few things. I also found this link which helped.
I used the function analogPinToChannel() to map the Arduino analog input to the correct hardware channel and it seems to be working fine. I assume that is the correct way to handle this?
New code below:
const byte arduinoAnalogPin = 0; //arduino analog input we want to use
int sensorValue;
void setup()
{
Serial.begin (115200);
ADCSRA = bit (ADEN); // turn ADC on
ADCSRA |= bit (ADPS0) | bit (ADPS1) | bit (ADPS2); // Prescaler of 128
ADMUX = bit (REFS0) | (analogPinToChannel(arduinoAnalogPin) & 0x07); //Vcc reference, hardware analog channel. Use analogPinToChannel() to map Arduino analog input to correct hardware channel
bitSet (ADCSRA, ADSC); // start first conversion
}
void loop()
{
delay(1000); // delay between reads for ADC to finish
//sensorValue = analogRead(A0); //use this for checking that hardware works
sensorValue = ADC; // read result (after delay of 1 second assume that conversion is complete
bitSet (ADCSRA, ADSC); // start next conversion
Serial.println (sensorValue);
}
Many thanks.