summaryrefslogtreecommitdiffstats
path: root/adc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'adc.cpp')
-rw-r--r--adc.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/adc.cpp b/adc.cpp
new file mode 100644
index 0000000..192d36c
--- /dev/null
+++ b/adc.cpp
@@ -0,0 +1,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)|(1<<ADLAR)|(port&0x07);
+ ADCSRA |= (1<<ADSC);
+
+ while(!(ADCSRA & (1<<ADIF)));
+
+ return ADC;
+}