GBALib_DCMotor is an Arduino library for managing DC motors using the L293D Motor Driver IC. It provides a simple and intuitive interface to control motor direction, speed, and runtime.
- Set motor speed: Adjust motor speed using PWM.
- Set motor direction: Automatically handles direction based on speed sign.
- Set runtime: Optionally run the motor for a specified duration.
- Simple interface: Intuitive methods for turning the motor on and off.
The library is included in the Arduino Library Manager. You can install it either by using the Library Manager or manually by following the steps below.
- Download or clone this repository:
git clone https://github.com/blasilli/GBALib_DCMotor.git
- Copy the
GBALib_DCMotorfolder into your Arduinolibrariesdirectory. - Restart the Arduino IDE to refresh the library index.
DCMotor(uint8_t pinA, uint8_t pinB, uint8_t pinS);- pinA: Pin connected to motor input A on the L293D.
- pinB: Pin connected to motor input B on the L293D.
- pinS: Pin connected to the enable pin (PWM) on the L293D.
Turns the motor on at the specified speed.
- speed: Speed of the motor (-255 to 255). Negative values reverse direction.
Turns the motor on at the specified speed for a given duration.
- speed: Speed of the motor (-255 to 255).
- millisec: Duration to run the motor in milliseconds.
Turns the motor off.
Here’s an example of how to use the library:
#include <GBALib_DCMotor.h>
// Initialize a DCMotor object with pins A=5, B=6, S=9
DCMotor motor(5, 6, 9);
void setup() {
// No setup required
}
void loop() {
motor.on(255); // Run the motor at full speed
delay(500); // Wait for 2 seconds
motor.off(); // Turn off the motor
delay(1000); // Wait for 2 seconds
motor.on(-255); // Run the motor at full speed in the opposite direction
delay(500); // Wait for 2 seconds
motor.off(); // Turn off the motor
delay(1000); // Wait for 2 seconds
}This library is licensed under the MIT License. See the LICENSE file for details.
