-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMotorExample.ino
93 lines (71 loc) · 1.73 KB
/
MotorExample.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* This example uses the ZumoMotors library to drive each motor on the Zumo
* forward, then backward. The yellow user LED is on when a motor should be
* running forward and off when a motor should be running backward. If a
* motor on your Zumo has been flipped, you can correct its direction by
* uncommenting the call to flipLeftMotor() or flipRightMotor() in the setup()
* function.
*/
#include <Wire.h>
#include <ZumoShield.h>
#define LED_PIN 13
ZumoMotors motors;
void setup()
{
pinMode(LED_PIN, OUTPUT);
// uncomment one or both of the following lines if your motors' directions need to be flipped
//motors.flipLeftMotor(true);
//motors.flipRightMotor(true);
}
void loop()
{
// run left motor forward
digitalWrite(LED_PIN, HIGH);
for (int speed = 0; speed <= 400; speed++)
{
motors.setLeftSpeed(speed);
delay(2);
}
for (int speed = 400; speed >= 0; speed--)
{
motors.setLeftSpeed(speed);
delay(2);
}
// run left motor backward
digitalWrite(LED_PIN, LOW);
for (int speed = 0; speed >= -400; speed--)
{
motors.setLeftSpeed(speed);
delay(2);
}
for (int speed = -400; speed <= 0; speed++)
{
motors.setLeftSpeed(speed);
delay(2);
}
// run right motor forward
digitalWrite(LED_PIN, HIGH);
for (int speed = 0; speed <= 400; speed++)
{
motors.setRightSpeed(speed);
delay(2);
}
for (int speed = 400; speed >= 0; speed--)
{
motors.setRightSpeed(speed);
delay(2);
}
// run right motor backward
digitalWrite(LED_PIN, LOW);
for (int speed = 0; speed >= -400; speed--)
{
motors.setRightSpeed(speed);
delay(2);
}
for (int speed = -400; speed <= 0; speed++)
{
motors.setRightSpeed(speed);
delay(2);
}
delay(500);
}