WebbotLib AVR library
WebbotLib It just does it
  C++ documentation  C documentation

Analogue Input

Performs analogue to digital conversion (ADC).
The ADC unit works with channels - each microprocessor will map a channel to a given pin. These pins are often the same ones as the standard I/O pins - but not always.
The number of channels available will also depend on your microprocessor.
To add an analogue input from Project Designer then drag the entry to your list of devices. This will open a window:
adc1.jpg
Change the name to something more meaningful to your project and select the ADC channel from the drop down list and then click Ok. Regenerate the code for your project and you will see some example code showing how to read the input. Note that you can always move the input to another channel in the drop down list and, so long as you don't change the name, then your code won't need modifying.
The ADC will, by default, be initialised with a prescaler of 64 and a reference voltage of AVCC. These settings are fine for general usage. Alternatively you can change the values at runtime with the a2dSetPrescaler and a2dSetReference commands.
There are times, e.g. a data acquisition/logging project, where you want to be able to read various inputs within a for loop and so accessing the inputs by name may not be ideal. In this case you can access the channel directly. For example: this will read all of the analogue channels on the board:
for(int i=0; i<NUM_ADC_CHANNELS;i++){
    a2dConvert8bit(ADC_NUMBER_TO_CHANNEL(i));
}
Function Summary