ME507 Airheads Project v1.1.0
Flight Stabilization for Glider
Loading...
Searching...
No Matches
potentiometer.h
Go to the documentation of this file.
1
9// Compile this header file only once
10#ifndef _POT_
11#define _POT_
12
13// Include appropriate modules
14#include <Arduino.h>
15
20{
21protected:
22 // Pin to read voltage from
23 uint8_t ADC_PIN;
24 // Range of ADC values determined by resolution (12 bit default)
25 const uint16_t ADC_RANGE = 4096;
26 // Voltage source to scale the ADC reading
27 const float VOLTAGE_SOURCE = 3.3;
28
29 // Offset to zero the potentiometer
31
32 // Voltage to angle conversion
33 float VOLTAGE_TO_DEGREES = 60;
34
35public:
36 // Setup object
37 Potentiometer(uint8_t pin, float offset);
38
39 // Value from ADC reading
40 uint16_t adc_value;
41
42 // Voltage from ADC reading
43 float voltage;
44
45 // Get the position of the potentiometer
46 float get_voltage(void);
47
48 // Get the position of the potentiometer
49 float get_angle(void);
50
51 // Zero the potentiometer
52 void zero(void);
53};
54
55#endif // _POT_
Class for a generic potentiometer which is used to determine its position.
Definition: potentiometer.h:20
uint8_t ADC_PIN
Pin to read voltage from (0 - 3.3V)
Definition: potentiometer.h:23
float voltage
Input voltage from ADC reading.
Definition: potentiometer.h:43
float get_angle(void)
The method to return the position of the potentiometer.
Definition: potentiometer.cpp:41
uint16_t adc_value
ADC value from the GPIO input pin.
Definition: potentiometer.h:40
float VOLTAGE_TO_DEGREES
Conversion from voltage to degrees determined experimentally.
Definition: potentiometer.h:33
const uint16_t ADC_RANGE
ADC range determined by a default 12 bit resolution.
Definition: potentiometer.h:25
float get_voltage(void)
The method to retrieve the voltage at the input pin.
Definition: potentiometer.cpp:27
void zero(void)
The method to zero the potentiometer to its current position.
Definition: potentiometer.cpp:58
float voltage_offset
The offset used to zero the potentiometer.
Definition: potentiometer.h:30
const float VOLTAGE_SOURCE
Voltage source reference to scale ADC reading.
Definition: potentiometer.h:27