Added arduino libs

هذا الالتزام موجود في:
Mik6e6
2020-07-04 12:31:18 -04:00
ملتزم من قبل GitHub
الأصل 3d9b49e518
التزام dc9596f994
90 ملفات معدلة مع 9419 إضافات و0 حذوفات

عرض الملف

@@ -0,0 +1,47 @@
#include "CytronMotorDriver.h"
CytronMD::CytronMD(MODE mode, uint8_t pin1, uint8_t pin2)
{
_mode = mode;
_pin1 = pin1;
_pin2 = pin2;
pinMode(_pin1, OUTPUT);
pinMode(_pin2, OUTPUT);
digitalWrite(_pin1, LOW);
digitalWrite(_pin2, LOW);
}
void CytronMD::setSpeed(int16_t speed)
{
// Make sure the speed is within the limit.
if (speed > 255) {
speed = 255;
} else if (speed < -255) {
speed = -255;
}
// Set the speed and direction.
switch (_mode) {
case PWM_DIR:
if (speed >= 0) {
analogWrite(_pin1, speed);
digitalWrite(_pin2, LOW);
} else {
analogWrite(_pin1, -speed);
digitalWrite(_pin2, HIGH);
}
break;
case PWM_PWM:
if (speed >= 0) {
analogWrite(_pin1, speed);
analogWrite(_pin2, 0);
} else {
analogWrite(_pin1, 0);
analogWrite(_pin2, -speed);
}
break;
}
}

عرض الملف

@@ -0,0 +1,44 @@
#ifndef CYTRON_MOTOR_DRIVER_H
#define CYTRON_MOTOR_DRIVER_H
#include <Arduino.h>
#include <stdint.h>
enum MODE {
PWM_DIR,
PWM_PWM,
};
class CytronMD
{
public:
CytronMD(MODE mode, uint8_t pin1, uint8_t pin2);
void setSpeed(int16_t speed);
protected:
MODE _mode;
uint8_t _pin1;
uint8_t _pin2;
};
/* class CytronMD10C : public CytronMD
{
public:
CytronMD10C(uint8_t pwmPin, uint8_t dirPin) : CytronMD(PWM_DIR, pwmPin, dirPin) {};
};
class CytronMD13S : public CytronMD
{
public:
CytronMD13S(uint8_t pwmPin, uint8_t dirPin) : CytronMD(PWM_DIR, pwmPin, dirPin) {};
}; */
#endif

عرض الملف

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2019 CytronTechnologies
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.

عرض الملف

@@ -0,0 +1,60 @@
# Arduino Library for Cytron Motor Drivers
This library provides functions for Cytron Motor Drivers.<br>
Please refer to the examples on how to use the library.<br>
Connection to the motor driver is described in the comment section of the examples.
## Installation
1. Open the Arduino IDE, select `Sketch` -> `Include Library` -> `Manage Libraries...`.
2. Search for `Cytron Motor Drivers Library`.
3. Click `Install` to install the library.
4. Restart the Arduino IDE.
5. Examples can be opened in Arduino IDE from `File` -> `Examples` -> `Cytron DC Motors Library`.<br>
Please refer to the example list below for all the compatible motor drivers.
## Examples
### 1. PWM_DIR
This example shows how to drive a motor using PWM and DIR pins.<br>
PWM pin is used to control the speed of the motor while DIR pin is used to control the direction.<br>
<br>
This example only show how to drive a single motor for simplicity.<br>
For multi channels motor driver, all channels work the same way.<br>
**Compatible Motor Drivers:**
* [MD10C](https://www.cytron.io/p-md10c)
* [MD10-POT](https://www.cytron.io/p-md10-pot)
* [MD13S](https://www.cytron.io/p-md13s)
* [MD20A](https://www.cytron.io/p-20amp-6v-30v-dc-motor-driver)
* [MD30C](https://www.cytron.io/p-md30c)
* [SHIELD-MD10](https://www.cytron.io/p-shield-md10)
* [MDS160A*](https://www.cytron.io/p-mds160a)
* [MDS40B*](https://www.cytron.io/p-mds40b)
**Smart series motor driver needs to be configured as **Sign-Magnitude PWM Input** mode. Refer to user manual for more details.*
### 2. PWM_DIR_DUAL
This example shows how to drive 2 motors using PWM and DIR pins .<br>
PWM pin is used to control the speed of the motor while DIR pin is used to control the direction.<br>
**Compatible Motor Drivers:**
* [SHIELD-2AMOTOR](https://www.cytron.io/p-shield-2amotor)
* [SHIELD-3AMOTOR](https://www.cytron.io/p-shield-3amotor)
* [MDD10A](https://www.cytron.io/p-mdd10a)
* [FD04A](https://www.cytron.io/p-fd04a)
* [MDDS10*](https://www.cytron.io/p-mdds10)
* [MDDS30*](https://www.cytron.io/p-mdds30)
* [MDDS60*](https://www.cytron.io/p-mdds60)
**Smart series motor driver needs to be configured as **Sign-Magnitude PWM Input** mode. Refer to user manual for more details.*
### 2. PWM_PWM_DUAL
This example shows how to drive 2 motors using 4 PWM input pins (2 for each motor).<br>
Input A controls the motor speed in forward direction and Input B controls the motor speed in backward direction.<br>
**Compatible Motor Drivers:**
* [MAKER-DRIVE](https://www.cytron.io/p-maker-drive)
* [MDD03A](https://www.cytron.io/p-mdd03a)

عرض الملف

@@ -0,0 +1,60 @@
/*******************************************************************************
* THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTY AND SUPPORT
* IS APPLICABLE TO THIS SOFTWARE IN ANY FORM. CYTRON TECHNOLOGIES SHALL NOT,
* IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR CONSEQUENTIAL
* DAMAGES, FOR ANY REASON WHATSOEVER.
********************************************************************************
* DESCRIPTION:
*
* This example shows how to drive a motor using the PWM and DIR pins.
* This example only shows how to drive a single motor for simplicity.
* For dual channel motor driver, both channel work the same way.
*
*
* CONNECTIONS:
*
* Arduino D3 - Motor Driver PWM Input
* Arduino D4 - Motor Driver DIR Input
* Arduino GND - Motor Driver GND
*
*
* AUTHOR : Kong Wai Weng
* COMPANY : Cytron Technologies Sdn Bhd
* WEBSITE : www.cytron.io
* EMAIL : support@cytron.io
*
*******************************************************************************/
#include "CytronMotorDriver.h"
// Configure the motor driver.
CytronMD motor(PWM_DIR, 3, 4); // PWM = Pin 3, DIR = Pin 4.
// The setup routine runs once when you press reset.
void setup() {
}
// The loop routine runs over and over again forever.
void loop() {
motor.setSpeed(128); // Run forward at 50% speed.
delay(1000);
motor.setSpeed(255); // Run forward at full speed.
delay(1000);
motor.setSpeed(0); // Stop.
delay(1000);
motor.setSpeed(-128); // Run backward at 50% speed.
delay(1000);
motor.setSpeed(-255); // Run backward at full speed.
delay(1000);
motor.setSpeed(0); // Stop.
delay(1000);
}

عرض الملف

@@ -0,0 +1,68 @@
/*******************************************************************************
* THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTY AND SUPPORT
* IS APPLICABLE TO THIS SOFTWARE IN ANY FORM. CYTRON TECHNOLOGIES SHALL NOT,
* IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR CONSEQUENTIAL
* DAMAGES, FOR ANY REASON WHATSOEVER.
********************************************************************************
* DESCRIPTION:
*
* This example shows how to drive 2 motors using the PWM and DIR pins with
* 2-channel motor driver.
*
*
* CONNECTIONS:
*
* Arduino D3 - Motor Driver PWM 1 Input
* Arduino D4 - Motor Driver DIR 1 Input
* Arduino D9 - Motor Driver PWM 2 Input
* Arduino D10 - Motor Driver DIR 2 Input
* Arduino GND - Motor Driver GND
*
*
* AUTHOR : Kong Wai Weng
* COMPANY : Cytron Technologies Sdn Bhd
* WEBSITE : www.cytron.io
* EMAIL : support@cytron.io
*
*******************************************************************************/
#include "CytronMotorDriver.h"
// Configure the motor driver.
CytronMD motor1(PWM_DIR, 3, 4); // PWM 1 = Pin 3, DIR 1 = Pin 4.
CytronMD motor2(PWM_DIR, 9, 10); // PWM 2 = Pin 9, DIR 2 = Pin 10.
// The setup routine runs once when you press reset.
void setup() {
}
// The loop routine runs over and over again forever.
void loop() {
motor1.setSpeed(128); // Motor 1 runs forward at 50% speed.
motor2.setSpeed(-128); // Motor 2 runs backward at 50% speed.
delay(1000);
motor1.setSpeed(255); // Motor 1 runs forward at full speed.
motor2.setSpeed(-255); // Motor 2 runs backward at full speed.
delay(1000);
motor1.setSpeed(0); // Motor 1 stops.
motor2.setSpeed(0); // Motor 2 stops.
delay(1000);
motor1.setSpeed(-128); // Motor 1 runs backward at 50% speed.
motor2.setSpeed(128); // Motor 2 runs forward at 50% speed.
delay(1000);
motor1.setSpeed(-255); // Motor 1 runs backward at full speed.
motor2.setSpeed(255); // Motor 2 runs forward at full speed.
delay(1000);
motor1.setSpeed(0); // Motor 1 stops.
motor2.setSpeed(0); // Motor 2 stops.
delay(1000);
}

عرض الملف

@@ -0,0 +1,68 @@
/*******************************************************************************
* THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTY AND SUPPORT
* IS APPLICABLE TO THIS SOFTWARE IN ANY FORM. CYTRON TECHNOLOGIES SHALL NOT,
* IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR CONSEQUENTIAL
* DAMAGES, FOR ANY REASON WHATSOEVER.
********************************************************************************
* DESCRIPTION:
*
* This example shows how to drive 2 motors using 4 PWM pins (2 for each motor)
* with 2-channel motor driver.
*
*
* CONNECTIONS:
*
* Arduino D3 - Motor Driver PWM 1A Input
* Arduino D9 - Motor Driver PWM 1B Input
* Arduino D10 - Motor Driver PWM 2A Input
* Arduino D11 - Motor Driver PWM 2B Input
* Arduino GND - Motor Driver GND
*
*
* AUTHOR : Kong Wai Weng
* COMPANY : Cytron Technologies Sdn Bhd
* WEBSITE : www.cytron.io
* EMAIL : support@cytron.io
*
*******************************************************************************/
#include "CytronMotorDriver.h"
// Configure the motor driver.
CytronMD motor1(PWM_PWM, 3, 9); // PWM 1A = Pin 3, PWM 1B = Pin 9.
CytronMD motor2(PWM_PWM, 10, 11); // PWM 2A = Pin 10, PWM 2B = Pin 11.
// The setup routine runs once when you press reset.
void setup() {
}
// The loop routine runs over and over again forever.
void loop() {
motor1.setSpeed(128); // Motor 1 runs forward at 50% speed.
motor2.setSpeed(-128); // Motor 2 runs backward at 50% speed.
delay(1000);
motor1.setSpeed(255); // Motor 1 runs forward at full speed.
motor2.setSpeed(-255); // Motor 2 runs backward at full speed.
delay(1000);
motor1.setSpeed(0); // Motor 1 stops.
motor2.setSpeed(0); // Motor 2 stops.
delay(1000);
motor1.setSpeed(-128); // Motor 1 runs backward at 50% speed.
motor2.setSpeed(128); // Motor 2 runs forward at 50% speed.
delay(1000);
motor1.setSpeed(-255); // Motor 1 runs backward at full speed.
motor2.setSpeed(255); // Motor 2 runs forward at full speed.
delay(1000);
motor1.setSpeed(0); // Motor 1 stops.
motor2.setSpeed(0); // Motor 2 stops.
delay(1000);
}

عرض الملف

@@ -0,0 +1,24 @@
#############################################
# Syntax Coloring Map For Cytron Motor Driver
#############################################
# Class
#############################################
CytronMD KEYWORD3
#############################################
# Methods and Functions
#############################################
setSpeed KEYWORD2
#############################################
# Constants
#############################################
PWM_DIR LITERAL1
PWM_PWM LITERAL1

عرض الملف

@@ -0,0 +1,9 @@
name=Cytron Motor Drivers Library
version=1.0.1
author=Cytron Technologies Sdn Bhd <support@cytron.io>
maintainer=Cytron Technologies Sdn Bhd <support@cytron.io>
sentence=Library for Cytron Motor Drivers.
paragraph=Provide examples on how to use the motor drivers.
category=Device Control
url=https://github.com/CytronTechnologies/CytronMotorDriver.git
architectures=*