From 4e25cc047bd968a9c1371aa3c77f33e1484ecbfa Mon Sep 17 00:00:00 2001 From: Rchurakov Date: Thu, 30 Mar 2023 17:00:05 +0300 Subject: [PATCH] potentiometer add --- potentiometer.c | 21 +++++++++++++++++++++ potentiometer.h | 7 +++++++ 2 files changed, 28 insertions(+) create mode 100644 potentiometer.c create mode 100644 potentiometer.h diff --git a/potentiometer.c b/potentiometer.c new file mode 100644 index 0000000..fe9e9d1 --- /dev/null +++ b/potentiometer.c @@ -0,0 +1,21 @@ +#include "potentiometer.h" +#include +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; +} diff --git a/potentiometer.h b/potentiometer.h new file mode 100644 index 0000000..1a28261 --- /dev/null +++ b/potentiometer.h @@ -0,0 +1,7 @@ +#ifndef POTENTIOMETER_H +#define POTENTIOMETER_H + +void pot_Initialization(void); +float get_pot_value(void); + +#endif /*POTENTIOMETER_H*/