-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pushed first example. Documentation in future commits…
- Loading branch information
Andrea Lombardo
authored and
Andrea Lombardo
committed
Jun 6, 2017
1 parent
ea3db8e
commit e1a4ac3
Showing
5 changed files
with
110 additions
and
7 deletions.
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,25 @@ | ||
# L298N | ||
A easy to use L298N library to control DC Motors with Arduino | ||
# L298N Library | ||
A easy to use L298N library to control DC Motors with Arduino. | ||
|
||
## NOTICE | ||
As you know, any L298N module have the ability to drive two motors at once, but you may know that any instance of the library is intended to pilot only one motor. So if you need to drive two motros, you have to instance two L298N object (one for each motor). | ||
|
||
## INSTALL THE LIBRARY | ||
Download this repository as a .zip file and from the Arduino IDE go to *Sketch -> Include library -> Add .ZIP Library* | ||
|
||
## IMPORT | ||
You can import the library in your code using the Arduino IDE going to *Sketch -> Include library -> L298N* | ||
or directly writing the include statement in your code: | ||
|
||
``` | ||
#include <L298N.h> | ||
``` | ||
## INSTANCE THE MODULE | ||
To drive a motor the first think is to create an istance of the library. | ||
``` | ||
L298N myMotor(EN, IN1, IN2); | ||
``` | ||
* EN = is the Arduino pin (required PWM pin) connected to the pin Enable of the module | ||
* IN1 and IN2 are two digital pin connected to IN1 and IN2 of the module | ||
|
||
*writing documentation stay tuned* |
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,63 @@ | ||
#include <L298N.h> | ||
|
||
//pin definition | ||
#define EN 9 | ||
#define IN1 8 | ||
#define IN2 7 | ||
|
||
//create a motor instance | ||
L298N motor(EN, IN1, IN2); | ||
|
||
void setup() { | ||
|
||
//used for display information | ||
Serial.begin(9600); | ||
|
||
motor.setSpeed(80); // an integer between 0 and 255 | ||
|
||
} | ||
|
||
void loop() { | ||
|
||
//tell the motor to go forward (may depend by your wiring) | ||
motor.forward(); | ||
|
||
//print the motor satus in the serial monitor | ||
Serial.print("Is moving = "); | ||
Serial.println(motor.isMoving()); | ||
|
||
delay(3000); | ||
|
||
//stop running | ||
motor.stop(); | ||
|
||
Serial.print("Is moving = "); | ||
Serial.println(motor.isMoving()); | ||
|
||
delay(3000); | ||
|
||
//change the initial speed | ||
motor.setSpeed(100); | ||
|
||
//tell the motor to go back (may depend by your wiring) | ||
motor.backward(); | ||
|
||
Serial.print("Is moving = "); | ||
Serial.println(motor.isMoving()); | ||
|
||
delay(3000); | ||
|
||
//stop running | ||
motor.stop(); | ||
|
||
Serial.print("Is moving = "); | ||
Serial.println(motor.isMoving()); | ||
|
||
//change the initial speed | ||
motor.setSpeed(255); | ||
|
||
Serial.print("Get new speed = "); | ||
Serial.println(motor.getSpeed()); | ||
|
||
delay(3000); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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