-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathdc.ino
43 lines (40 loc) · 1003 Bytes
/
dc.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "Emakefun_MotorDriver.h"
Emakefun_MotorDriver mMotor = Emakefun_MotorDriver(0x60);
Emakefun_DCMotor *DCMotor_1 = mMotor.getMotor(M1);
Emakefun_DCMotor *DCMotor_2 = mMotor.getMotor(M2);
Emakefun_DCMotor *DCMotor_3 = mMotor.getMotor(M3);
Emakefun_DCMotor *DCMotor_4 = mMotor.getMotor(M4);
void setup()
{
Serial.begin(9600);
mMotor.begin(50);
}
void loop()
{
// 前进
DCMotor_1->setSpeed(200);
DCMotor_1->run(FORWARD);
DCMotor_2->setSpeed(200);
DCMotor_2->run(FORWARD);
DCMotor_3->setSpeed(200);
DCMotor_3->run(FORWARD);
DCMotor_4->setSpeed(200);
DCMotor_4->run(FORWARD);
delay(4000);
// 后退
DCMotor_1->setSpeed(100);
DCMotor_1->run(BACKWARD);
DCMotor_2->setSpeed(100);
DCMotor_2->run(BACKWARD);
DCMotor_3->setSpeed(100);
DCMotor_3->run(BACKWARD);
DCMotor_4->setSpeed(100);
DCMotor_4->run(BACKWARD);
delay(4000);
// 刹车
DCMotor_1->run(BRAKE);
DCMotor_2->run(BRAKE);
DCMotor_3->run(BRAKE);
DCMotor_4->run(BRAKE);
delay(4000);
}