-
Notifications
You must be signed in to change notification settings - Fork 61
/
MotorTest.ino
83 lines (73 loc) · 1.73 KB
/
MotorTest.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
/* This example drives 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 <Zumo32U4.h>
Zumo32U4Motors motors;
Zumo32U4ButtonA buttonA;
void setup()
{
// Uncomment if necessary to correct motor directions:
//motors.flipLeftMotor(true);
//motors.flipRightMotor(true);
// Wait for the user to press button A.
buttonA.waitForButton();
// Delay so that the robot does not move away while the user is
// still touching it.
delay(1000);
}
void loop()
{
// Run left motor forward.
ledYellow(1);
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.
ledYellow(0);
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.
ledYellow(1);
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.
ledYellow(0);
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);
}