-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit ecba04f
Showing
6 changed files
with
113 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Simon Pucheu | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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 @@ | ||
# Motor |
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,30 @@ | ||
####################################### | ||
# Syntax Coloring Map | ||
####################################### | ||
|
||
####################################### | ||
# Datatypes (KEYWORD1) | ||
####################################### | ||
|
||
Motor KEYWORD1 | ||
|
||
####################################### | ||
# Methods and Functions (KEYWORD2) | ||
####################################### | ||
|
||
forward KEYWORD2 | ||
backward KEYWORD2 | ||
|
||
####################################### | ||
# Variables (KEYWORD3) | ||
####################################### | ||
|
||
pin1 KEYWORD3 | ||
pin2 KEYWORD3 | ||
min KEYWORD3 | ||
max KEYWORD3 | ||
reversed KEYWORD3 | ||
|
||
###################################### | ||
# Constants (LITERAL1) | ||
####################################### |
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=Motor | ||
version=1.0.0 | ||
author=Simon Pucheu | ||
maintainer=Simon Pucheu | ||
sentence=None | ||
paragraph=None | ||
category=Sensors | ||
url=https://github.com/6moon9/Motor | ||
architectures=avr | ||
includes=Motor.h | ||
depends= |
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,35 @@ | ||
#include <Arduino.h> | ||
|
||
#include "Motor.h" | ||
|
||
/** | ||
* Setup the Motor | ||
*/ | ||
Motor::Motor(uint8_t iPin1, uint8_t iPin2, bool iReversed = false, int iMin = 0, int iMax = 1023) | ||
{ | ||
pin1 = iPin1; | ||
pin2 = iPin2; | ||
reversed = iReversed; | ||
min = iMin; | ||
max = iMax; | ||
pinMode(pin1, OUTPUT); | ||
pinMode(pin2, OUTPUT); | ||
} | ||
|
||
void Motor::forward(int speed) | ||
{ | ||
analogWrite(pin1, map(speed, min, max, 0, 255)); | ||
digitalWrite(pin2, LOW); | ||
} | ||
|
||
void Motor::backward(int speed) | ||
{ | ||
digitalWrite(pin1, LOW); | ||
analogWrite(pin2, map(speed, min, max, 0, 255)); | ||
} | ||
|
||
void Motor::stop() | ||
{ | ||
digitalWrite(pin1, LOW); | ||
digitalWrite(pin2, LOW); | ||
} |
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,15 @@ | ||
#include <Arduino.h> | ||
|
||
class Motor | ||
{ | ||
public: | ||
Motor(uint8_t iPin1, uint8_t iPin2, bool iReversed = false, int iMin = 0, int iMax = 1023); | ||
void forward(int speed); | ||
void backward(int speed); | ||
void stop(); | ||
uint8_t pin1; | ||
uint8_t pin2; | ||
int min = 0; | ||
int max = 1023; | ||
bool reversed = false; | ||
}; |