-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMA3Analog.h
52 lines (39 loc) · 1.11 KB
/
MA3Analog.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef MA3ANALOG_H
#define MA3ANALOG_H
#include "RoveEncoder.h"
#include <cstdint>
class MA3Analog : public RoveEncoder {
private:
uint8_t m_pin;
mutable float m_minAnalog = 0, m_maxAnalog = 1023;
bool m_autoRecalibrate = false;
/**
* @brief Convert the input analog value to degrees.
*
* @param analog Value to convert.
* @return Equivalent reading in degrees.
*/
float analogToDegrees(float analog) const;
public:
/**
* @brief Construct a new MA3Analog object.
*
* @param pin The Arduino pin number to use.
*/
MA3Analog(uint8_t pin) : m_pin(pin) {}
/**
* @brief Configure the values used to convert Arduino analogRead() to degrees.
*
* @param minAnalog The minimum analog signal, defaults to 0.
* @param maxAnalog The maximum analog signal, defaults to 1023.
* @param autoRecalibrate Allow adjustment of minAnalog and maxAnalog if they are ever exceeded.
*/
void configCalibration(float minAnalog, float maxAnalog, bool autoRecalibrate);
/**
* @brief Read the encoder value in degrees.
*
* @return Current degree value [0, 360).
*/
float readDegrees() const;
};
#endif