Skip to content

Commit 57ecfc4

Browse files
author
HackerInside0
committed
Committed release v1.0.0
1 parent 089f23c commit 57ecfc4

File tree

7 files changed

+257
-1
lines changed

7 files changed

+257
-1
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
# L293
2-
Arduino library
2+
Library for the control of bidirectional motors and not by the integrated circuit L293
3+
4+
Created by Giuseppe Masino, 28 may 2016
5+
Author URL http://www.facebook.com/peppe.masino1
6+
7+
This library and the relative example files are released under the license
8+
CreativeCommons Attribution-ShareAlike 4.0 International
9+
10+
License info: http://creativecommons.org/licenses/by-sa/4.0/
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Bidirectional Motor Control
3+
*
4+
* Example of using L293 library to control one or more DC Birirectional Motors
5+
*
6+
* Created by Giuseppe Masino, 25 may 2016
7+
* Author URL http://www.facebook.com/peppe.masino1
8+
*
9+
* This example and the L293 library are released under the license
10+
* CreativeCommons ShareAlike-Attribution
11+
*
12+
* -----------------------------------------------------------------------------------
13+
*
14+
* Things that you need:
15+
* - Arduino\Genuino MEGA2560
16+
* (any Arduino\Genuino board can be used, the important is that the L293 pin 1 is connected to a PWM-enabled pin of Arduino)
17+
* (on the Arduino MEGA2560 all pins from 2 to 13 are PWM-enabled)
18+
* (use of pin 13 is discouraged because it can cause issues when the board resets)
19+
*
20+
* - L293
21+
* - A DC Birirectional Motor (max 5V-4mA)
22+
* - A breadboard
23+
*
24+
*
25+
* The circuit:
26+
* - Arduino pin 2 -> L293 pin 1
27+
* - Arduino pin 3 -> L293 pin 2
28+
* - Arduino pin 4 -> L293 pin 7
29+
* - Arduino GND -> L293 pin 4, 5
30+
* - Arduino 5V -> L293 pin 16, 8
31+
*
32+
* - L293 pin 3 -> a terminal of the motor
33+
* - L293 pin 6 -> the other terminal of the motor
34+
*
35+
*/
36+
37+
//import the library in the sketch
38+
#include <L293.h>
39+
40+
//these variables are constants and won't change
41+
//give a name to the pins that we use
42+
const int speedPin = 2; //that is the pin that we use to control the motor's speed
43+
const int forwardPin = 3; //this is the pin that we use to tell the motor to go forward
44+
const int reversePin = 4; //this is the pin that we use to tell the motor to go reverse
45+
46+
//make a new istance of the L293 library and call it "motor"
47+
//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
48+
L293 motor(speedPin,forwardPin,reversePin);
49+
50+
void setup()
51+
{
52+
//nothing to do in setup()
53+
}
54+
55+
void loop()
56+
{
57+
motor.forward(255); //set the direction and the speed of the motor
58+
delay(1000); //wait for 1 second before doing else
59+
motor.back(255); //set a new direction and the speed of the motor
60+
delay(1000); //wait for 1 second before doing else
61+
motor.stop(); //stop the motor
62+
delay(1000); //wait for 1 second before doing else
63+
64+
//now the loop restarts
65+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Serial Bidirectional Motor Control
3+
*
4+
* Example of using L293 library to control one or more DC Birirectional Motors via the Serial line
5+
*
6+
* Created by Giuseppe Masino, 28 may 2016
7+
* Author URL http://www.facebook.com/peppe.masino1
8+
*
9+
* This example and the L293 library are released under the license
10+
* CreativeCommons ShareAlike-Attribution 4.0 International
11+
*
12+
* License info: http://creativecommons.org/licenses/by-sa/4.0/
13+
*
14+
* -----------------------------------------------------------------------------------
15+
*
16+
* Things that you need:
17+
* - Arduino\Genuino MEGA2560
18+
* (any Arduino\Genuino board can be used, the important is that the L293 pin 1 is connected to a PWM-enabled pin of Arduino)
19+
* (on the Arduino MEGA2560 all pins from 2 to 13 are PWM-enabled)
20+
* (use of pin 13 is discouraged because it can cause issues when the board resets)
21+
*
22+
* - L293
23+
* - A DC Birirectional Motor (max 5V-4mA)
24+
* - A breadboard
25+
*
26+
*
27+
* The circuit:
28+
* - Arduino pin 2 -> L293 pin 1
29+
* - Arduino pin 3 -> L293 pin 2
30+
* - Arduino pin 4 -> L293 pin 7
31+
* - Arduino GND -> L293 pin 4, 5
32+
* - Arduino 5V -> L293 pin 16, 8
33+
*
34+
* - L293 pin 3 -> a terminal of the motor
35+
* - L293 pin 6 -> the other terminal of the motor
36+
*
37+
*/
38+
39+
//import the library in the sketch
40+
#include <L293.h>
41+
42+
//these are constants and won't change
43+
//give a name to the pins that you use
44+
const int speedPin = 2; //that is the pin that we use to control the motor's speed
45+
const int forwardPin = 3; //this is the pin that we use to tell the motor to go forward
46+
const int reversePin = 4; //this is the pin that we use to tell the motor to go reverse
47+
48+
//make a new istance of the L293 library and call it "motor"
49+
//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
50+
L293 motor(speedPin,forwardPin,reversePin);
51+
52+
void setup()
53+
{
54+
//these istructions will be executed one time
55+
56+
Serial.begin(9600); //enable serial communication
57+
}
58+
59+
void loop()
60+
{
61+
if(Serial.available() > 0) //check if there is an incoming command on the serial line
62+
{
63+
String command = Serial.readString(); //store the command in a variable
64+
65+
//select the proper action
66+
if(command == "forward") motor.forward(255);
67+
else if(command == "reverse") motor.back(255);
68+
else if(command == "stop") motor.stop();
69+
}
70+
}

keywords.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#######################################
2+
# Class (KEYWORD1)
3+
# Methods and Functions (KEYWORD2)
4+
# Constants (LITERAL1)
5+
#######################################
6+
7+
L293 KEYWORD1
8+
forward KEYWORD2
9+
back KEYWORD2
10+
stop KEYWORD2
11+
setSpeedOffset KEYWORD2

library.properties

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name=L293
2+
version=1.0.0
3+
author=Giuseppe Masino <http://www.facebook.com/peppe.masino1>
4+
maintainer=Giuseppe Masino <http://www.facebook.com/peppe.masino1>
5+
sentence=Allow to control brushless motors with L293 motor driver
6+
paragraph=
7+
category=Device Control
8+
url=https://github.com/HackerInside0/L293.git
9+
architectures=*
10+
dot_a_linkage=true
11+
includes=L293.h

src/L293.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include <L293.h>
2+
3+
L293::L293(uint8_t _enablePin, uint8_t _forwardPin, uint8_t _backPin)
4+
{
5+
enablePin = _enablePin;
6+
forwardPin = _forwardPin;
7+
reversePin = _backPin;
8+
9+
pinMode(enablePin, OUTPUT);
10+
pinMode(forwardPin, OUTPUT);
11+
pinMode(reversePin, OUTPUT);
12+
13+
speedOffset = 0;
14+
}
15+
16+
L293::L293(uint8_t _enablePin, uint8_t _forwardPin, uint8_t _backPin, uint8_t _speedOffset)
17+
{
18+
enablePin = _enablePin;
19+
forwardPin = _forwardPin;
20+
reversePin = _backPin;
21+
22+
pinMode(enablePin, OUTPUT);
23+
pinMode(forwardPin, OUTPUT);
24+
pinMode(reversePin, OUTPUT);
25+
26+
speedOffset = _speedOffset;
27+
}
28+
29+
void L293::forward(uint8_t _pwm)
30+
{
31+
this->stop();
32+
digitalWrite(forwardPin, HIGH);
33+
analogWrite(enablePin, _pwm + speedOffset);
34+
}
35+
36+
void L293::back(uint8_t _pwm)
37+
{
38+
if(reversePin == 255) return this->forward(_pwm);
39+
this->stop();
40+
digitalWrite(reversePin, HIGH);
41+
analogWrite(enablePin, _pwm + speedOffset);
42+
}
43+
44+
void L293::stop()
45+
{
46+
analogWrite(enablePin, 0);
47+
digitalWrite(forwardPin, LOW);
48+
if(reversePin != 255) digitalWrite(reversePin, LOW);
49+
}
50+
51+
void L293::setSpeedOffset(uint8_t _speedOffset)
52+
{
53+
speedOffset = _speedOffset;
54+
}

src/L293.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* L293
3+
* Library for the control of bidirectional motors and not by the integrated circuit L293
4+
*
5+
* Created by Giuseppe Masino, 28 may 2016
6+
* Author URL http://www.facebook.com/peppe.masino1
7+
*
8+
* This library and the relative example files are released under the license
9+
* CreativeCommons ShareAlike-Attribution 4.0 International
10+
*
11+
* License info: http://creativecommons.org/licenses/by-sa/4.0/
12+
*
13+
*/
14+
15+
#ifndef l293_lib
16+
#define l293_lib
17+
18+
#include <Arduino.h>
19+
20+
class L293
21+
{
22+
public:
23+
24+
L293(byte _enablePin, byte _forwardPin, byte _backPin);
25+
L293(byte _enablePin, byte _forwardPin, byte _backPin, byte _speedOffset);
26+
27+
void forward(byte _pwm);
28+
void back(byte _pwm);
29+
void stop(void);
30+
void setSpeedOffset(byte _speedOffset);
31+
32+
private:
33+
34+
uint8_t enablePin, forwardPin, reversePin, speedOffset;
35+
};
36+
37+
#endif

0 commit comments

Comments
 (0)