1.FilteredAnalog
This examples shows how to filter an analog input, so you can get the position of a knob or fader without noise.
- Boards:
- AVR, AVR USB, Nano Every, Nano 33 IoT, Nano 33 BLE, UNO R4, Pi Pico, Due, Teensy 3.x, ESP8266, ESP32
Connections
- A0: wiper of a potentiometer
Connect the left terminal of the potentiometer to ground, and the right one to VCC.
Behavior
- Upload the sketch to the Arduino, and open the Serial Monitor (
CTRL+Shift+M
)
- When you turn the potentiometer, you should see the position of the potentiometer being printed as a number between 0 and 1023.
- The analog input is filtered, so there shouldn't be any noise on the position. If there is, check your wiring, and make sure that the resistance of the potentiometer isn't too high (10 kΩ is ideal).
The example 1.FilteredAnalog-Advanced.ino has more information about the parameters you can pass to the FilteredAnalog class to tweak the filters, increase the resolution, etc.
Written by PieterP, 2019-10-10
https://github.com/tttapa/Arduino-Helpers
void setup() {
Serial.begin(115200);
while (!Serial);
}
void loop() {
}
Dummy header file for Arduino builder.
A class that reads and filters an analog input.
void resetToCurrentValue()
Reset the filtered value to the value that's currently being measured at the analog input.
static void setupADC()
Select the configured ADC resolution.
AnalogType getValue() const
Get the filtered value of the analog input (with the mapping function applied).
bool update()
Read the analog input value, apply the mapping function, and update the average.
A class for easily managing timed events.