potentiometer add
This commit is contained in:
parent
27e20c0bf1
commit
4e25cc047b
21
potentiometer.c
Normal file
21
potentiometer.c
Normal file
@ -0,0 +1,21 @@
|
||||
#include "potentiometer.h"
|
||||
#include <avr/io.h>
|
||||
int pot_value;
|
||||
|
||||
void pot_Initialization() {
|
||||
ADMUX |= 0B00000101;
|
||||
ADMUX |= 0B01000000;
|
||||
ADCSRA |= 0B11000000;
|
||||
ADCSRA |= (1 << ADIE);
|
||||
sei();
|
||||
ADCSRA |= 0B01000000;
|
||||
}
|
||||
|
||||
ISR (ADC_vect) {
|
||||
pot_value = ADCL | (ADCH << 8);
|
||||
ADCSRA |= 0B01000000;
|
||||
}
|
||||
|
||||
float get_pot_value() {
|
||||
return pot_value * 0.00498046875;
|
||||
}
|
7
potentiometer.h
Normal file
7
potentiometer.h
Normal file
@ -0,0 +1,7 @@
|
||||
#ifndef POTENTIOMETER_H
|
||||
#define POTENTIOMETER_H
|
||||
|
||||
void pot_Initialization(void);
|
||||
float get_pot_value(void);
|
||||
|
||||
#endif /*POTENTIOMETER_H*/
|
Loading…
Reference in New Issue
Block a user