Skip to content

sensenmann/EZHaptic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Logo

GitHub Stars GitHub Forks License Platform Language Last Commit

EZHaptic

An easy-to-use vibration control library for ESP32 using native hardware timers and PWM.

Table of Contents

Features

  • 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

Quickstart

#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
}

Usage

Constructor

EZHaptic(uint8_t motorPin, timer_group_t group = TIMER_GROUP_0, timer_idx_t idx = TIMER_0);
  • motorPin: GPIO pin for the motor
  • group: Timer group (default TIMER_GROUP_0)
  • idx: Timer index (default TIMER_0)

Public Methods

Method Description
begin Initializes PWM and timer
play Starts pattern execution
playRepeated Starts pattern execution with given repetition count
stop Stops current pattern

Pattern Language

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.

Predefined Patterns

const static String BzzBzz = "xxx.xx..";
const static String LongRing = "xxxxxxxx        xxxxxxxx        ";

Use them directly:

haptic.play(BzzBzz);

About

An easy-to-use vibration control library for ESP32 using native hardware timers and PWM.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages