-
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
1 parent
725a712
commit cb58b18
Showing
4 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
examples/forward_brake_backward/forward_brake_backward.ino
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,23 @@ | ||
#include "MotorController.h" | ||
|
||
|
||
MotorController motor = MotorController(2, 3, 4); | ||
|
||
|
||
void setup() | ||
{ | ||
|
||
} | ||
|
||
|
||
void loop() | ||
{ | ||
motor.write(255); | ||
delay(5000); | ||
|
||
motor.brake(); | ||
delay(5000); | ||
|
||
motor.write(-255); | ||
delay(5000); | ||
} |
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,9 @@ | ||
name=MotorController | ||
version=1.0.0 | ||
author=PowerBroker2 <[email protected]> | ||
maintainer=PowerBroker2 <[email protected]> | ||
sentence=Easy to use Arduino library to control virtually any DC motor controller | ||
paragraph=Easy to use Arduino library to control virtually any DC motor controller | ||
category=Device Control | ||
url=https://github.com/PowerBroker2/ELMduino | ||
architectures=* |
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,78 @@ | ||
#include "MotorController.h" | ||
|
||
|
||
|
||
|
||
MotorController::MotorController(const byte& _pwmPin, const byte& _in1, const byte& _in2) | ||
{ | ||
pwmPin = _pwmPin; | ||
in1 = _in1; | ||
in2 = _in2; | ||
|
||
pinMode(pwmPin, OUTPUT); | ||
pinMode(in1, OUTPUT); | ||
pinMode(in2, OUTPUT); | ||
} | ||
|
||
|
||
|
||
|
||
void MotorController::write(const int& _speed) | ||
{ | ||
if (_speed > 0) | ||
forward(_speed); | ||
else | ||
reverse(_speed); | ||
} | ||
|
||
|
||
|
||
|
||
void MotorController::forward(const int& _speed) | ||
{ | ||
speed = _speed; | ||
digitalWrite(in1, HIGH); | ||
digitalWrite(in2, LOW); | ||
analogWrite(pwmPin, speed); | ||
} | ||
|
||
|
||
|
||
|
||
void MotorController::brake() | ||
{ | ||
speed = 0; | ||
digitalWrite(in1, LOW); | ||
digitalWrite(in2, LOW); | ||
analogWrite(pwmPin, speed); | ||
} | ||
|
||
|
||
|
||
|
||
void MotorController::free() | ||
{ | ||
speed = 0; | ||
digitalWrite(in1, HIGH); | ||
digitalWrite(in2, HIGH); | ||
analogWrite(pwmPin, speed); | ||
} | ||
|
||
|
||
|
||
|
||
void MotorController::reverse(const int& _speed) | ||
{ | ||
speed = _speed; | ||
digitalWrite(in1, LOW); | ||
digitalWrite(in2, HIGH); | ||
analogWrite(pwmPin, speed); | ||
} | ||
|
||
|
||
|
||
|
||
int MotorController::read() | ||
{ | ||
return speed; | ||
} |
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,23 @@ | ||
#pragma once | ||
#include "Arduino.h" | ||
|
||
|
||
|
||
|
||
class MotorController | ||
{ | ||
public: | ||
MotorController(const byte& _pwmPin, const byte& _in1, const byte& _in2); | ||
void write(const int& _speed); | ||
void forward(const int& _speed); | ||
void brake(); | ||
void free(); | ||
void reverse(const int& _speed); | ||
int read(); | ||
|
||
private: | ||
int speed; | ||
byte pwmPin; | ||
byte in1; | ||
byte in2; | ||
}; |