/*
Ardumoto
Example
Sketch
by:
Jim
Lindblom
date:
November
8,
2013
license:
Public
domain.
Please
use,
reuse,
and
modify
this
sketch!
Adapted
to
v20
hardware
by:
Marshall
Taylor
date:
March
31,
2017
Three
useful
functions
are
defined:
setupArdumoto()
Setup
the
Ardumoto
Shield
pins
driveArdumoto([motor],
[direction],
[speed])
Drive
[mot
or]
(0
for
A,
1
for
B)
in
[direction]
(0
or
1)
at
a
[speed]
between
0
and
255.
It
will
spin
until
told
to
stop.
stopArdumoto([motor])
Stop
driving
[motor]
(0
or
1).
setupArdumoto()
is
called
in
the
setup().
The
loop()
demonstrates
use
of
the
motor
driving
functions.
*/
//
Clockwise
and
counter
clockwise
definitions.
//
Depending
on
how
you
wired
your
motors,
you
may
need
to
swa
p.
#define
FORWARD
0
#define
REVERSE
1
//
Motor
definitions
to
make
life
easier:
#define
MOTOR_A
0
#define
MOTOR_B
1
//
Pin
Assignments
//
//Default
pins:
#define
DIRA
2
//
Direction
control
for
motor
A
#define
PWMA
3
//
PWM
control
(speed)
for
motor
A
#define
DIRB
4
//
Direction
control
for
motor
B
#define
PWMB
11
//
PWM
control
(speed)
for
motor
B
////Alternate
pins:
//#define
DIRA
8
//
Direction
control
for
motor
A
//#define
PWMA
9
//
PWM
control
(speed)
for
motor
A
//#define
DIRB
7
//
Direction
control
for
motor
B
//#define
PWMB
10
//
PWM
control
(speed)
for
motor
B
void setup()
{
setupArdumoto();
//
Set
all
pins
as
outputs
}
void loop()
{
//
Drive
motor
A
(and
only
motor
A)
at
various
speeds,
then
stop.
driveArdumoto(MOTOR_A,
REVERSE,
255);
//
Set
motor
A
to
REVE
RSE
at
max
delay(1000);
//
Motor
A
will
spin
as
set
for
1
second
driveArdumoto(MOTOR_A,
FORWARD,
127);
//
Set
motor
A
to
FOR
WARD
at
half
delay(1000);
//
Motor
A
will
keep
trucking
for
1
second
stopArdumoto(MOTOR_A);
//
STOP
motor
A
//
Drive
motor
B
(and
only
motor
B)
at
various
speeds,
then
stop.
Page 12 of 17