We are excited to unveil the latest addition to the AvantMaker family of ESP32 Arduino libraries: AvantDigitalRead, a powerful and versatile library designed to revolutionize digital input management on the ESP32. Crafted with makers, hobbyists, and developers in mind, AvantDigitalRead enhances the standard Arduino digitalRead
functionality, offering advanced features like multi-pin management, event detection, and sophisticated gesture recognition.
What’s AvantDigitalRead All About?
AvantDigitalRead is a comprehensive solution for managing digital inputs on the ESP32. Whether you’re building interactive user interfaces, handling sensor data, or creating complex IoT devices, this library simplifies the process with a clean, intuitive interface. It takes the hassle out of debouncing, event handling, and gesture detection, allowing you to focus on bringing your creative projects to life.
Key features include:
- Multi-pin Management: Easily add or remove pins for unified control.
- Built-in Debouncing: Customizable debounce times for reliable input readings.
- Rich Event Detection: Detect state changes, rising edges, and falling edges with ease.
- Advanced Button Gestures: Recognize single-press, double-press, and long-press events with configurable timings.
- Non-Blocking Design: Keep your
loop()
clean and responsive. - Unified Callback Format: Simplify your code with consistent event handling.
This library is perfect for a wide range of applications, including:
- Interactive Interfaces: Create responsive buttons and switches for user controls.
- Sensor Integration: Reliably read data from sensors in IoT projects.
- Smart Devices: Build intuitive controls for home automation and robotics.
Why We Built AvantDigitalRead
At AvantMaker, our mission is to empower the maker community with tools that are both powerful and accessible. We recognized that managing digital inputs on the ESP32 often involves repetitive, error-prone code for debouncing and event detection. AvantDigitalRead abstracts away this complexity, providing a robust, non-blocking solution that ensures stable input handling and simplifies gesture recognition.
This library is designed to be a cornerstone for our upcoming ESP32 tutorials, particularly those integrating hardware control with IoT and AI applications. With AvantDigitalRead, you can build reliable, responsive projects with confidence, freeing you to experiment and innovate.
A Glimpse of What You Can Do
Imagine creating a smart device that detects a single button press to toggle a light, a double press to adjust brightness, or a long press to activate a special mode. With AvantDigitalRead, these complex interactions become simple and reliable.
Here’s a quick example to demonstrate its power:
#include "AvantDigitalRead.h"
// Define the pin to monitor
#define BUTTON_PIN 5
// Create an instance of AvantDigitalRead
AvantDigitalRead pinManager;
void setup() {
// Initialize serial communication
Serial.begin(115200);
while (!Serial) {
; // Wait for serial port to connect
}
// Print welcome message
Serial.println("BasicButtonMonitor Example Starting...");
Serial.print("Monitoring pin for button presses: ");
Serial.println(BUTTON_PIN);
Serial.println("Press the button to see single/double/long press notifications.");
Serial.println("----------------------------------------");
// Initialize the pin to monitor
if (pinManager.addPin(BUTTON_PIN, INPUT_PULLUP)) {
Serial.println("Pin initialized successfully");
} else {
Serial.println("Failed to initialize pin");
while (1) {
delay(100); // Halt execution if pin initialization fails
}
}
// Set debounce time to prevent false triggers (30 milliseconds)
pinManager.setDebounceTime(BUTTON_PIN, 30);
// Set click parameters (optional, using default values here)
// pinManager.setClickParameters(BUTTON_PIN, 50, 300, 500);
// Parameters: minPressMs, maxPressMs, maxIntervalMs
// Set long press duration (optional, default is 1000ms)
// pinManager.setLongPressDuration(BUTTON_PIN, 1000);
// Register the callback functions for single, double, and long press events
pinManager.onSinglePress(BUTTON_PIN, singlePressCallback);
pinManager.onDoublePress(BUTTON_PIN, doublePressCallback);
pinManager.onLongPress(BUTTON_PIN, longPressCallback);
Serial.println("Ready for input.");
Serial.println("----------------------------------------");
}
void loop() {
// Must call update() regularly to process events
pinManager.update();
// Small delay to prevent excessive CPU usage
delay(10);
}
// Callback function for single press events
void singlePressCallback(int pin, PinState newState, PinState oldState,
EventType event, unsigned long timestamp) {
// Print pin information
Serial.print("Pin ");
Serial.print(pin);
Serial.print(" SINGLE PRESS detected: ");
Serial.print(oldState);
Serial.print(" -> ");
Serial.print(newState);
// Print timestamp
Serial.print(" at ");
Serial.print(timestamp);
Serial.println(" ms");
// Additional information
Serial.println(" Event: Button pressed and released once");
}
// Callback function for double press events
void doublePressCallback(int pin, PinState newState, PinState oldState,
EventType event, unsigned long timestamp) {
// Print pin information
Serial.print("Pin ");
Serial.print(pin);
Serial.print(" DOUBLE PRESS detected: ");
Serial.print(oldState);
Serial.print(" -> ");
Serial.print(newState);
// Print timestamp
Serial.print(" at ");
Serial.print(timestamp);
Serial.println(" ms");
// Additional information
Serial.println(" Event: Button pressed and released twice in quick succession");
}
// Callback function for long press events
void longPressCallback(int pin, PinState newState, PinState oldState,
EventType event, unsigned long timestamp) {
// Print pin information
Serial.print("Pin ");
Serial.print(pin);
Serial.print(" LONG PRESS detected: ");
Serial.print(oldState);
Serial.print(" -> ");
Serial.print(newState);
// Print timestamp
Serial.print(" at ");
Serial.print(timestamp);
Serial.println(" ms");
// Additional information
Serial.println(" Event: Button held down for extended duration");
}
What’s Next for AvantDigitalRead?
This is just the beginning! AvantDigitalRead will play a key role in our upcoming ESP32 Arduino tutorials, where we’ll showcase its integration with AI-powered projects and IoT applications.
Our goal is to make AvantDigitalRead the go-to library for ESP32 digital input management, empowering makers to create more intuitive and responsive projects.
Get Started Today!
Ready to streamline your digital input code and unlock new possibilities? Head over to the AvantDigitalRead GitHub Repository to download the library, explore the examples, and dive into the full API documentation.
You can install AvantDigitalRead via the Arduino IDE Library Manager, or download the ZIP file for manual installation. Check out the “Quick Start” section in the README for step-by-step instructions.
We encourage you to try AvantDigitalRead in your projects, experiment with its features, and share your feedback. Your input helps us improve and grow—feel free to open issues, suggest features, or contribute to the project.
Explore our growing collection of libraries and tutorials at the AvantMaker GitHub or dive into our resources at AvantMaker.com.
Happy Making! 🛠️✨