Skip to content

blasilli/GBALib_DCMotor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GBALib_DCMotor

Arduino Logo

Overview

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.

Features

  • 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.

Installation

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.

  1. Download or clone this repository:
    git clone https://github.com/blasilli/GBALib_DCMotor.git
  2. Copy the GBALib_DCMotor folder into your Arduino libraries directory.
  3. Restart the Arduino IDE to refresh the library index.

API Reference

Constructor

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.

Methods

on(int speed)

Turns the motor on at the specified speed.

  • speed: Speed of the motor (-255 to 255). Negative values reverse direction.

on(int speed, unsigned long millisec)

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.

off()

Turns the motor off.

Example Usage

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

}

License

This library is licensed under the MIT License. See the LICENSE file for details.

About

DC Motor Management Library using the L293D Motor Driver IC

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages