This is an old revision of the document!
Esta biblioteca fornece funções para usar o conversor analógico para digital do AVR. Todas as funções desta biblioteca bloqueiam o processador até chegarem ao resultado. O tempo de conversão depende do relógio ADC.
Initializes ADC. Parameters:
Converts specified ADC channel analog value to digital. Function is blocking. Parameter:
Converts specified ADC channel analog value to digital desired number of times and calculates the average. Function is blocking. Parameters:
For example ADC is initialized and two analog channel values are converted to digital. Value of channel 0 is assigned to variable x and averaged value of channel 1 to variable y.
#include <homelab/adc.h> int main(void) { unsigned short x, y; // Initializing ADC. Reference voltage from AVCC. // Clock is 8 times slower than system clock. adc_init(ADC_REF_AVCC, ADC_PRESCALE_8); // Converting channel 0 value. x = adc_get_value(0); // Converting and averaging channel 1 value. y = adc_get_average_value(1, 10); }