/***************************************************
Motor Test - PM-R3 Motor Drive
MA DIR-D4 PWM-D5;
MB DIR-D7 PWM-D6;
motor driver library: [url=https://github.com/YFROBOT-TM/Yfrobot-Motor-Driver-Library]https://github.com/YFROBOT-TM/Yfrobot-Motor-Driver-Library[/url]
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:
* [url=http://arduino.cc/en/Tutorial/Tone]http://arduino.cc/en/Tutorial/Tone[/url]
**********************************************************/
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() {
}