An easy-to-use vibration control library for ESP32 using native hardware timers and PWM.
- Control vibration motors using ESP32's native hardware timers
- Pattern-based vibration control with 125ms intervals
- PWM support for different vibration intensities
- No external libraries required
- Clean object-oriented C++ design
- Easy integration into existing projects
#include "EZHaptic.h"
EZHaptic haptic(5); // GPIO 5 for motor output
void setup() {
haptic.begin();
haptic.play("x__o_.. x__o_.. !");
}
void loop() {
// Nothing to do – runs independently using a hardware timer
}EZHaptic(uint8_t motorPin, timer_group_t group = TIMER_GROUP_0, timer_idx_t idx = TIMER_0);motorPin: GPIO pin for the motorgroup: Timer group (defaultTIMER_GROUP_0)idx: Timer index (defaultTIMER_0)
| Method | Description |
|---|---|
begin |
Initializes PWM and timer |
play |
Starts pattern execution |
playRepeated |
Starts pattern execution with given repetition count |
stop |
Stops current pattern |
Each pattern is a String, where each character is processed every 125ms:
| Character | Action |
|---|---|
x |
Full power vibration |
o |
Medium power vibration |
. |
Light vibration |
_ |
Motor off |
! |
Immediately stops the pattern (optional) |
You can define and play your own vibration sequences using combinations of these characters.
const static String BzzBzz = "xxx.xx..";
const static String LongRing = "xxxxxxxx xxxxxxxx ";Use them directly:
haptic.play(BzzBzz);