-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
HackerInside0
committed
Sep 13, 2016
1 parent
089f23c
commit 57ecfc4
Showing
7 changed files
with
257 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |