Control Surface  1.2.0
MIDI Control Surface library for Arduino
1.FilteredAnalog.ino

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, Due, Teensy 3.x, ESP8266, ESP32

Connections

Connect the left terminal of the potentiometer to ground, and the right one to VCC.

Behavior

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

// Include the library
// Create a filtered analog object on pin A0, with the default settings:
FilteredAnalog<> analog = A0;
void setup() {
Serial.begin(115200);
while (!Serial)
;
// Select the correct ADC resolution
analog.setupADC();
}
void loop() {
// Read the analog input every millisecond, and print if the value has changed
static Timer<millis> timer = 1; // ms
if (timer && analog.update())
Serial.println(analog.getValue());
}
// Explanation:
//
// analog.update() reads the analog input, applies the filters,
// saves the value, and returns true if the value has changed.
// You can then retreive the new value using analog.getValue().
//
// Timer is just a "Blink Without Delay" wrapper, it returns true
// every time the specified amount of time has passed.
MillisMicrosTimer.hpp
Arduino_Helpers.h
Dummy header file for Arduino builder.
FilteredAnalog.hpp