To start using CoilCell, create an instance of the CoilCell class by specifying the input pins connected to your actuator, and then call the Init() function. Here’s a basic setup example:
#include "CoilCell.h"
CoilCell myCoilCell(IN1, IN2); // Replace IN1 and IN2 with your specific pins
void setup() {
myCoilCell.Init(); // Initializes the CoilCell
}The CoilCell library offers a range of functions to control the coil. Below are detailed descriptions of the available functions:
- Description: Initializes the CoilCell by setting up the GPIO pins and, if using an ESP32, attaches hardware timers for precise control.
myCoilCell.Init(); // Initializes the CoilCell
- Description for ESP32: Flips the polarity of the actuator at the specified speed and duty cycle. The
smoothparameter creates smoother transitions ideal for slow motions. - Examples:
myCoilCell.Vibrate(true, 50, 500); // Smooth operation at 50% power, flipping every 500 ms
- Description for Other Arduino Devices: Uses simple GPIO toggling with delay to flip the actuator polarity at 100% duty cycle.
- Examples:
myCoilCell.Vibrate(500); // Flip every 500 milliseconds
- Description: Generates a buzzing effect by toggling the actuator state at the specified microsecond intervals, ideal for creating sound or rapid vibrations.
- Example:
myCoilCell.Buzz(100); // Buzz at 100 microseconds
- Description for ESP32: Controls the speed and polarity of a coil using PWM.
- Examples:
myCoilCell.Drive(true, 75); // Drive forward at 75% power
- Description: Creates a short bounce motion by quickly reversing polarity for the specified duration.
- Example:
myCoilCell.Bounce(true, 10); // Bounce in one direction for 10 milliseconds
- Description: Plays a tone by continuously toggling the coil state with varying frequencies, useful for generating audible feedback.
- Example:
myCoilCell.Tone(); // Play a tone with varying frequencies
-
Description for ESP32: Toggles the polarity of the coil at the desired duty cycle using PWM.
-
Examples:
myCoilCell.Toggle(50); // Toggle direction at 50% power
-
Description for Other Arduino Devices: Toggles polarity using simple GPIO toggling.
-
Examples:
myCoilCell.Toggle(); // Toggle direction or polarity
