summaryrefslogtreecommitdiffstats
path: root/adc.cpp
blob: f7d5e0421705d425843e788c9cbe609953ac6108 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "adc.h"

#include <avr/io.h>


void initADC() {
  ADMUX = (1<<REFS0); 
  ADCSRA = (1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0); 
}

uint16_t getADCValue(int port) {
  ADMUX = (1<<REFS0)|(port&0x07);
  ADCSRA |= (1<<ADSC);
  
  while(!(ADCSRA & (1<<ADIF)));
  
  return ADC;
}