Skip to content

Commit

Permalink
First example
Browse files Browse the repository at this point in the history
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
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 7 deletions.
27 changes: 25 additions & 2 deletions README.md
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*
63 changes: 63 additions & 0 deletions examples/L298N-Simple/L298N-Simple.ino
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);
}
Binary file added examples/L298N-Simple/Schema_bb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 17 additions & 1 deletion keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@
# Syntax Coloring Map For L298N
#######################################

#######################################
# Datatypes (KEYWORD1)
#######################################

L298N KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
#######################################

setSpeed KEYWORD2
getSpeed KEYWORD2
forward KEYWORD2
Expand All @@ -12,4 +20,12 @@ backward KEYWORD2
backwardFor KEYWORD2
stop KEYWORD2
reset KEYWORD2
isMoving KEYWORD2
isMoving KEYWORD2

#######################################
# Instances (KEYWORD2)
#######################################

#######################################
# Constants (LITERAL1)
#######################################
9 changes: 5 additions & 4 deletions library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ name=L298N
version=1.0.0
author=Andrea Lombardo
maintainer=Andrea Lombardo
sentence=Gestire motori DC con il modulo L298N
paragraph=Semplice libreria per la gestione di motori DC con il modulo L298N
sentence=L298N library for Arduino
paragraph=An easy way to control DC Motors with Arduino and the L298N module.
category=Device Control
url=http://www.lombardoandrea.com
architectures=*
url=https://github.com/AndreaLombardo/L298N
architectures=*
includes=L298N.h

0 comments on commit e1a4ac3

Please sign in to comment.