Skip to content

Commit

Permalink
Committed release v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
HackerInside0 committed Sep 13, 2016
1 parent 089f23c commit 57ecfc4
Show file tree
Hide file tree
Showing 7 changed files with 257 additions and 1 deletion.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
# L293
Arduino library
Library for the control of bidirectional motors and not by the integrated circuit L293

Created by Giuseppe Masino, 28 may 2016
Author URL http://www.facebook.com/peppe.masino1

This library and the relative example files are released under the license
CreativeCommons Attribution-ShareAlike 4.0 International

License info: http://creativecommons.org/licenses/by-sa/4.0/
65 changes: 65 additions & 0 deletions examples/MotorControl/MotorControl.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Bidirectional Motor Control
*
* Example of using L293 library to control one or more DC Birirectional Motors
*
* Created by Giuseppe Masino, 25 may 2016
* Author URL http://www.facebook.com/peppe.masino1
*
* This example and the L293 library are released under the license
* CreativeCommons ShareAlike-Attribution
*
* -----------------------------------------------------------------------------------
*
* Things that you need:
* - Arduino\Genuino MEGA2560
* (any Arduino\Genuino board can be used, the important is that the L293 pin 1 is connected to a PWM-enabled pin of Arduino)
* (on the Arduino MEGA2560 all pins from 2 to 13 are PWM-enabled)
* (use of pin 13 is discouraged because it can cause issues when the board resets)
*
* - L293
* - A DC Birirectional Motor (max 5V-4mA)
* - A breadboard
*
*
* The circuit:
* - Arduino pin 2 -> L293 pin 1
* - Arduino pin 3 -> L293 pin 2
* - Arduino pin 4 -> L293 pin 7
* - Arduino GND -> L293 pin 4, 5
* - Arduino 5V -> L293 pin 16, 8
*
* - L293 pin 3 -> a terminal of the motor
* - L293 pin 6 -> the other terminal of the motor
*
*/

//import the library in the sketch
#include <L293.h>

//these variables are constants and won't change
//give a name to the pins that we use
const int speedPin = 2; //that is the pin that we use to control the motor's speed
const int forwardPin = 3; //this is the pin that we use to tell the motor to go forward
const int reversePin = 4; //this is the pin that we use to tell the motor to go reverse

//make a new istance of the L293 library and call it "motor"
//then show what are the pins used to control speed, to tell the motor to go forward and to tell the motor to go reverse
L293 motor(speedPin,forwardPin,reversePin);

void setup()
{
//nothing to do in setup()
}

void loop()
{
motor.forward(255); //set the direction and the speed of the motor
delay(1000); //wait for 1 second before doing else
motor.back(255); //set a new direction and the speed of the motor
delay(1000); //wait for 1 second before doing else
motor.stop(); //stop the motor
delay(1000); //wait for 1 second before doing else

//now the loop restarts
}
70 changes: 70 additions & 0 deletions examples/SerialMotorControl/SerialMotorControl.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Serial Bidirectional Motor Control
*
* Example of using L293 library to control one or more DC Birirectional Motors via the Serial line
*
* Created by Giuseppe Masino, 28 may 2016
* Author URL http://www.facebook.com/peppe.masino1
*
* This example and the L293 library are released under the license
* CreativeCommons ShareAlike-Attribution 4.0 International
*
* License info: http://creativecommons.org/licenses/by-sa/4.0/
*
* -----------------------------------------------------------------------------------
*
* Things that you need:
* - Arduino\Genuino MEGA2560
* (any Arduino\Genuino board can be used, the important is that the L293 pin 1 is connected to a PWM-enabled pin of Arduino)
* (on the Arduino MEGA2560 all pins from 2 to 13 are PWM-enabled)
* (use of pin 13 is discouraged because it can cause issues when the board resets)
*
* - L293
* - A DC Birirectional Motor (max 5V-4mA)
* - A breadboard
*
*
* The circuit:
* - Arduino pin 2 -> L293 pin 1
* - Arduino pin 3 -> L293 pin 2
* - Arduino pin 4 -> L293 pin 7
* - Arduino GND -> L293 pin 4, 5
* - Arduino 5V -> L293 pin 16, 8
*
* - L293 pin 3 -> a terminal of the motor
* - L293 pin 6 -> the other terminal of the motor
*
*/

//import the library in the sketch
#include <L293.h>

//these are constants and won't change
//give a name to the pins that you use
const int speedPin = 2; //that is the pin that we use to control the motor's speed
const int forwardPin = 3; //this is the pin that we use to tell the motor to go forward
const int reversePin = 4; //this is the pin that we use to tell the motor to go reverse

//make a new istance of the L293 library and call it "motor"
//then show what are the pins used to control speed, to tell the motor to go forward and to tell the motor to go reverse
L293 motor(speedPin,forwardPin,reversePin);

void setup()
{
//these istructions will be executed one time

Serial.begin(9600); //enable serial communication
}

void loop()
{
if(Serial.available() > 0) //check if there is an incoming command on the serial line
{
String command = Serial.readString(); //store the command in a variable

//select the proper action
if(command == "forward") motor.forward(255);
else if(command == "reverse") motor.back(255);
else if(command == "stop") motor.stop();
}
}
11 changes: 11 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#######################################
# Class (KEYWORD1)
# Methods and Functions (KEYWORD2)
# Constants (LITERAL1)
#######################################

L293 KEYWORD1
forward KEYWORD2
back KEYWORD2
stop KEYWORD2
setSpeedOffset KEYWORD2
11 changes: 11 additions & 0 deletions library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name=L293
version=1.0.0
author=Giuseppe Masino <http://www.facebook.com/peppe.masino1>
maintainer=Giuseppe Masino <http://www.facebook.com/peppe.masino1>
sentence=Allow to control brushless motors with L293 motor driver
paragraph=
category=Device Control
url=https://github.com/HackerInside0/L293.git
architectures=*
dot_a_linkage=true
includes=L293.h
54 changes: 54 additions & 0 deletions src/L293.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <L293.h>

L293::L293(uint8_t _enablePin, uint8_t _forwardPin, uint8_t _backPin)
{
enablePin = _enablePin;
forwardPin = _forwardPin;
reversePin = _backPin;

pinMode(enablePin, OUTPUT);
pinMode(forwardPin, OUTPUT);
pinMode(reversePin, OUTPUT);

speedOffset = 0;
}

L293::L293(uint8_t _enablePin, uint8_t _forwardPin, uint8_t _backPin, uint8_t _speedOffset)
{
enablePin = _enablePin;
forwardPin = _forwardPin;
reversePin = _backPin;

pinMode(enablePin, OUTPUT);
pinMode(forwardPin, OUTPUT);
pinMode(reversePin, OUTPUT);

speedOffset = _speedOffset;
}

void L293::forward(uint8_t _pwm)
{
this->stop();
digitalWrite(forwardPin, HIGH);
analogWrite(enablePin, _pwm + speedOffset);
}

void L293::back(uint8_t _pwm)
{
if(reversePin == 255) return this->forward(_pwm);
this->stop();
digitalWrite(reversePin, HIGH);
analogWrite(enablePin, _pwm + speedOffset);
}

void L293::stop()
{
analogWrite(enablePin, 0);
digitalWrite(forwardPin, LOW);
if(reversePin != 255) digitalWrite(reversePin, LOW);
}

void L293::setSpeedOffset(uint8_t _speedOffset)
{
speedOffset = _speedOffset;
}
37 changes: 37 additions & 0 deletions src/L293.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* L293
* Library for the control of bidirectional motors and not by the integrated circuit L293
*
* Created by Giuseppe Masino, 28 may 2016
* Author URL http://www.facebook.com/peppe.masino1
*
* This library and the relative example files are released under the license
* CreativeCommons ShareAlike-Attribution 4.0 International
*
* License info: http://creativecommons.org/licenses/by-sa/4.0/
*
*/

#ifndef l293_lib
#define l293_lib

#include <Arduino.h>

class L293
{
public:

L293(byte _enablePin, byte _forwardPin, byte _backPin);
L293(byte _enablePin, byte _forwardPin, byte _backPin, byte _speedOffset);

void forward(byte _pwm);
void back(byte _pwm);
void stop(void);
void setSpeedOffset(byte _speedOffset);

private:

uint8_t enablePin, forwardPin, reversePin, speedOffset;
};

#endif

0 comments on commit 57ecfc4

Please sign in to comment.