Product Introduction

1/17/2018 FireBeetle Covers-DC Motor & Stepper Driver SKU:DFR0508 - DFRobot Electronic Product Wiki and Tutorial: Arduino and Robot Wiki-DFRobot…
https://www.dfrobot.com/wiki/index.php/FireBeetle_Covers-DC_Motor_%26_Stepper_Driver_SKU:DFR0508#More 5/12
/*!
* @file Motor.ino
* @brief DFRobot's Motor Drive
* @n The example demonstrates four groups D.C motors work together
at the same time, contains operations such as rotation, speed
adjustment, brakes and so on.
* @copyright [DFRobot](http://www.dfrobot.com), 2016
* @copyright GNU Lesser General Public License
* @author [LiXin]
* @version V1.0
* @date 2017-7-31
* @https://github.com/DFRobot/DFRobot_MotorStepper
*/
#include "Arduino.h"
#include "Wire.h"
#include "DFRobot_MotorStepper.h"
/*****************Keywords instruction*****************/
//M1--->motor_Group_1--->[M1A(+),M1B(-)]
//M2--->motor_Group_2--->[M2A(+),M1B(-)]
//M3--->motor_Group_3--->[M3A(+),M3B(-)]
//M4--->motor_Group_4--->[M4A(+),M4B(-)]
//CW: rotate in positive direction
//CCW: rotate in reverse
//A0: Chip Selection Address 1
//A1: Chip Selection Address 2
//A2: Chip Selection Address 3
//A3: Chip Selection Address 4
/*****************Function instruction*****************/
//void start(uint8_t dir)
//*This function can be used to start the motor
//*dir: Set Orientation CW or CCW
//void speed(uint16_t val)
//*This function is used to set the motor speed
//*val: Set the speed 0<=val<=4096
//void stop()
//*This function is used to stop the motor turning
DFRobot_Motor motor1(M1,A0);
void setup() {
//initialize serial communication at 9600 bits per second:
Serial.begin(115200);
//join i2c bus (address optional for master)
Wire.begin();
//Initialize D.C motor drive chip (Group1)
motor1.init();
}
void loop()
{
//Setting initial velocity(Min:0 Max:4096)
motor1.speed(4096);
//Motor1 rotate in positive direction
motor1.start(CW);
delay(2000);
//All motors rotate in reverse
motor1.start(CCW);
delay(2000);
//All motors brake and stop rotating
motor1.stop();
delay(2000);
}
Program Function: the first group rotate in C.W.(Clockwise) for 2s and rotate in anti-clockwise for 2s, then stop for 2s and followed by recycling.
Functions:
1. Create a motor object
DFRobot_Motor motor1(M1) M1 represents the first group DC motor M1A(+),M1B(-)
2. Initiate the motor drive, read Product ID and Version ID, and print to the serial port.
init()
3. Set speed
speed(val) 0<=val<=4096(the maximum speed is 4096)