Arduino library · Data and time

ResponsiveAnalogRead: an example that runs

Yes. You can use the ResponsiveAnalogRead library online in Mokxi with nothing to install, and the sketch runs in your browser against the simulated part (Potentiometer). The example below, "A potentiometer read with ResponsiveAnalogRead", runs on the Arduino Uno R3.

Built in on Mokxi: #include <ResponsiveAnalogRead.h> and it builds, with nothing to install. Free, and no account needed.

What ResponsiveAnalogRead does

Update(), getValue() and hasChanged(): an analog reading smoothed when steady, quick when it moves, and still when asleep. That is what ResponsiveAnalogRead, by Damien Clarke, covers. The sketch below uses it on the Arduino Uno: “A potentiometer read with ResponsiveAnalogRead”.

Damien Clarke's ResponsiveAnalogRead library, an analog reading smoothed when it is steady and quick when it moves.

It reads Mokxi's potentiometer (or any analog part).

The calls follow release 1.2.1 of the library, so a sketch written here builds on a real board too. The example is the one Mokxi's own tests build and run, so what is printed here is what runs.

Library Manager nameResponsiveAnalogRead
AuthorDamien Clarke
Include#include <ResponsiveAnalogRead.h>
BoardsArduino Uno, Arduino Nano, Arduino Mega 2560, Arduino Leonardo, SparkFun Pro Micro, Arduino Micro, WCH CH32V003, ATtiny85, Raspberry Pi Pico, Raspberry Pi Pico W, Seeed XIAO SAMD21, STM32, STM32 Nucleo-F411RE, Arduino Uno R4, ESP32 DevKit, ESP32-S3-DevKitC-1, ESP8266 NodeMCU, Arduino Pro Mini 3.3 V, Seeed XIAO ESP32-C3, Seeed XIAO ESP32-C6, ESP32-DevKitC V4, LOLIN32 Lite, Wemos D1 R32, Cheap Yellow Display, TTGO T-Display, Seeed XIAO ESP32-S3, Arduino Nano ESP32, Arduino Nano RP2040 Connect, Seeed XIAO RP2040, Waveshare RP2040-Zero, Arduino Uno R4 WiFi
In the simulatorSimulated: it runs against the part the way it does on the bench.
Parts it drivesPotentiometer

Install it

It builds on Arduino Uno, Arduino Nano, Arduino Mega 2560, Arduino Leonardo, SparkFun Pro Micro, Arduino Micro, WCH CH32V003, ATtiny85, Raspberry Pi Pico, Raspberry Pi Pico W, Seeed XIAO SAMD21, STM32, STM32 Nucleo-F411RE, Arduino Uno R4, ESP32 DevKit, ESP32-S3-DevKitC-1, ESP8266 NodeMCU, Arduino Pro Mini 3.3 V, Seeed XIAO ESP32-C3, Seeed XIAO ESP32-C6, ESP32-DevKitC V4, LOLIN32 Lite, Wemos D1 R32, Cheap Yellow Display, TTGO T-Display, Seeed XIAO ESP32-S3, Arduino Nano ESP32, Arduino Nano RP2040 Connect, Seeed XIAO RP2040, Waveshare RP2040-Zero, Arduino Uno R4 WiFi.

In Mokxi it is built in: #include <ResponsiveAnalogRead.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board, install "ResponsiveAnalogRead" by Damien Clarke from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add ResponsiveAnalogRead to lib_deps in PlatformIO. Mokxi follows the calls of release 1.2.1, so a sketch written here builds there too.

What to know in the simulator: The snap curve and sleep follow upstream’s description; the numbers may differ from upstream’s in the last count or two.

The calls you will use

In the order a sketch meets them.

ResponsiveAnalogRead analog(ANALOG_PIN, true)

Makes analog, the ResponsiveAnalogRead object the calls below are made on.

analog.update()

Updates it.

analog.hasChanged()

Returns true or false for "has changed".

analog.getValue()

Returns the value as a whole number.

Example: A potentiometer read with ResponsiveAnalogRead

On the Arduino Uno R3. It runs in the browser exactly as printed.

sketch.ino · Arduino Uno R3
#include <ResponsiveAnalogRead.h>

const int ANALOG_PIN = A0;
ResponsiveAnalogRead analog(ANALOG_PIN, true);

void setup() {
  Serial.begin(9600);
}

void loop() {
  analog.update();
  if (analog.hasChanged()) {
    Serial.print("value ");
    Serial.println(analog.getValue());
  }
  delay(20);
}

Wiring

  • Arduino Uno R3 5V to Potentiometer 1
  • Arduino Uno R3 GND to Potentiometer 3
  • Arduino Uno R3 A0 to Potentiometer 2

Open it in the editor, wired and ready to run

Try ResponsiveAnalogRead without installing anything

Open the example, change the sketch, and keep your version in a free account.