Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonPucheu committed Nov 20, 2022
0 parents commit ecba04f
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
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.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Motor
30 changes: 30 additions & 0 deletions keywords.txt
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)
#######################################
11 changes: 11 additions & 0 deletions library.properties
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=
35 changes: 35 additions & 0 deletions src/Motor.cpp
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);
}
15 changes: 15 additions & 0 deletions src/Motor.h
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;
};

0 comments on commit ecba04f

Please sign in to comment.