The Arduino VibrationMotor library provides a simple and modular way to manage a vibration motor connected to an Arduino board. The library includes functions for running both simple and complex vibration patterns, making it easy to integrate vibration feedback into your Arduino projects.
-
Download the Library:
- Click on the "Code" button in the GitHub repository.
- Select "Download ZIP" to download the library as a ZIP file.
-
Extract the ZIP File:
- Extract the contents of the ZIP file to your Arduino libraries directory.
-
Restart the Arduino IDE:
- Restart the Arduino IDE to ensure that the library is recognized.
-
Include the Library:
#include <VibrationMotor.h>
-
Instantiate the VibrationMotor object:
const int motorPin = 5; // Specify the pin to which the vibration motor is connected VibrationMotor myVibrationMotor(motorPin);
-
Constructor
// Initialize the VibrationMotor with the specified Arduino pin. VibrationMotor(uint8_t motorPin);
-
Turn the Motor On
void on(); Turn the vibration motor on.
-
Turn the Motor On with Intensity
void on(uint8_t intensity);
-
Turn the Motor Off
void off();
-
Pulse (Short On-Off)
void pulse();
-
Pulse with Repetitions
void pulse(int repetitions);
-
Pulse for a Specified Time (Custom On-Off)
void pulseFor(int time);
-
Fade In Effect
void fadeIn();
-
Fade Out Effect
void fadeOut();
