1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <avr/io.h> #include "pins.h" void init_adc() { PRR = 0; DDRF = 0; //enable ADC0 input, refrence is AREF (wire to 5v) ADMUX = 0b01100000; //enable adc, disable interrupts, clear pending reading, slowest speed ADCSRA = 0b10000111; } uint8_t analog_read_8bit() { ADCSRA |= (1 << ADSC); while(ADCSRA & (1 << ADSC)); return ADCH; }