FilteredAnalogIn¶
- template <uint16_t depth>
- class
A low pass filtered analog input pin.
This is a class built upon the standard mbed::AnalogIn class, that include running average low pass filtering.
Filtered analog inputs
In almost all cases you should low pass filter an incoming analog signal, to remove high frequency noise. This class is a convenient way to do that. It uses the RunningAverageFilter to filter all incoming samples.
Just like the RunningAverageFilter, this class is templated with the length of the low pass filter.
Example
Here we create 32 sample long filter, attached to the 3.5mm jack connector input pin:
FilteredAnalogIn<32> input(J_RING1); uint16_t filteredSample = input.read_u16();
Public Functions
-
mono::io::FilteredAnalogIn::
FilteredAnalogIn
(PinName pin)¶ Create an AnalogIn, connected to the specified pin.
- Parameters
pin
-AnalogIn pin to connect to
-
float
mono::io::FilteredAnalogIn::
read
()¶ Read the input voltage, represented as a float in the range [0.0, 1.0].
The value is filtered through a running average filter Complexity: O(1)
- Return
- A floating-point value representing the current input voltage, measured as a percentage
-
unsigned short
mono::io::FilteredAnalogIn::
read_u16
()¶ Read the input voltage, represented as an unsigned short in the range [0x0, 0xFFFF].
The value is filtered through a running average filter Complexity: O(1)
- Return
- 16-bit unsigned short representing the current input voltage, normalised to a 16-bit value
-