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, Due, Nano 33 IoT, Nano 33 BLE, UNO R4, Pi Pico, Teensy 3.x, ESP32, ESP8266
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).
Mapping
None.
Written by PieterP, 2019-10-10
https://github.com/tttapa/Control-Surface
FilteredAnalog<10,
2,
uint16_t
>
analog = A0;
FilteredAnalog<10,
6,
uint32_t
>
moreFiltering = A0;
FilteredAnalog<> simpleAnalog = A0;
void setup() {
Serial.begin(115200);
while (!Serial)
;
FilteredAnalog<>::setupADC();
analog.invert();
}
void loop() {
static Timer<millis> timer = 1;
if (timer && analog.update())
Serial.println(analog.getValue());
}
The main header file that includes all Control-Surface header files.