Input | Output | |||||
IN1 | IN2 | PWM | STBY | OUT1 | OUT2 | Mode |
H | H | H/L | H | L | L | Short break |
L | H | H | H | L | H | CCW |
L | H | L | L | Short break | ||
H | L | H | H | H | L | CW |
L | H | L | L | Short break | ||
L | L | H | H | OFF(High impedance) | Stop | |
H/L | H/L | H/L | L | OFF(High impedance) | Standby |
PIN | I/O | DESCRIPTION | |
NAME | NO. | ||
1A | 1 | I | Gate 1 logic signal |
1Y | 6 | O | Gate 1 inverted signal |
2A | 3 | I | Gate 2 logic signal |
2Y | 4 | O | Gate 2 inverted signal |
GND | 2 | — | Ground |
VCC | 5 | — | Supply / Power Pin |
DIRA(D4) | PWMA(D5) | DIRB(D7) | PWMB(D6) | AO1/AO2 |
H | H | H | H | 正转 |
L | H | L | H | 反转 |
X | L | X | L | 刹车 |
X为任意电平 |
void setMotor(int MOTORA,int MOTORB)
{
if(MOTORA>0) //判断方向,大于0表示正向
{
digitalWrite(DIRA,HIGH); //DIRA引脚置高
analogWrite(PWMA,MOTORA); //PWMA输入PWM信号
//PWM是高电平的占空比,这里需要取反,所以255 + MOTORA
}
else if //判断方向,小于0表示反向
{
digitalWrite(DIRA,LOW);
analogWrite(PWMA,- MOTORA); //PWM是高电平的占空比
//这里需要取反,这时MOTORA为负值,所以255 - MOTORA
}
else //等于0表示停止
{
digitalWrite(DIRA,LOW);
analogWrite(PWMA,LOW);
}
if(MOTORB>0) //判断方向,大于0表示正向
{
digitalWrite(DIRB,HIGH); //DIRB引脚置高
analogWrite(PWMB,MOTORB); //PWMB输入PWM信号
//PWM是高电平的占空比,这里需要取反,所以255 + MOTORB
}
else if //判断方向,小于0表示反向
{
digitalWrite(DIRB,LOW);
analogWrite(PWMB,- MOTORB); //PWM是高电平的占空比
//这里需要取反,这时MOTORB为负值,所以255 - MOTORB
}
else //等于0表示停止
{
digitalWrite(DIRB,LOW);
analogWrite(PWMB,LOW);
}
}
/***************************************************
Motor Test - PM-R3 Motor Drive
MA DIR-D4 PWM-D5;
MB DIR-D7 PWM-D6;
motor driver library: https://github.com/YFROBOT-TM/Yfrobot-Motor-Driver-Library
YFROBOT ZL
08/13/2020
****************************************************/
#include <MotorDriver.h>
#define MOTORTYPE YF_PMR3
uint8_t SerialDebug = 1; // 串口打印调试 0-否 1-是
// these constants are used to allow you to make your motor configuration
// line up with function names like forward. Value can be 1 or -1
const int offseta = 1;
const int offsetb = 1;
// Initializing motors.
MotorDriver motorDriver = MotorDriver(MOTORTYPE);
void setup() {
Serial.begin(9600);
Serial.println("Motor Drive test!");
motorDriver.motorConfig(offseta, offsetb);
}
void loop() {
motorDriver.setMotor(255, 255); // 电机AB 全速正转
delay(500);
motorDriver.setMotor(0, 0); // 电机AB停止
delay(500);
motorDriver.setMotor(-255, -255); // 电机AB 全速反转
delay(500);
motorDriver.setMotor(0, 0); // 电机AB停止
delay(1000);
}
/**********************************************************
* Play Super Mario theme song with arduino and speaker
*
* circuit:
* 8-ohm speaker on digital pin 12
* reference:
* http://arduino.cc/en/Tutorial/Tone
**********************************************************/
int melody[]={330,330,330,262,330,392,196};
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[]={8,4,4,8,4,2,2};
void setup() {
// iterate over the notes of the melody:
for (int thisNote = 0; thisNote < 7; thisNote++) {
// to calculate the note duration, take one second divided by the note type.
int noteDuration = 1000/noteDurations[thisNote];
tone(12, melody[thisNote],noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
noTone(12); // stop the tone playing:
}
}
void loop() {
}
欢迎光临 YFROBOT创客社区 (http://82.157.198.105/) | Powered by Discuz! X3.1 |