potentiometer add

This commit is contained in:
Rchurakov 2023-03-30 17:00:05 +03:00
parent 27e20c0bf1
commit 4e25cc047b
2 changed files with 28 additions and 0 deletions

21
potentiometer.c Normal file
View 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
View File

@ -0,0 +1,7 @@
#ifndef POTENTIOMETER_H
#define POTENTIOMETER_H
void pot_Initialization(void);
float get_pot_value(void);
#endif /*POTENTIOMETER_H*/