4) Creating a Test Program
Start by testing the movement of your ant using this
simple test program. Save your initial sketch, for example,
under the name "variAnt_test.ino".
First create an object of the VariAnt class in the program
and give it a name like "ant", for example.
Within the setup function, the "ant" object needs to be
initialized using its own setup function.
Use "setSpeed(160)" to set the starting speed to 160, for
example. The highest possible value is 255.
For controlling the motors and polling the sensors, the
"ant.update()" function must always be called within
the loop function.
The if statement uses the "buttonPressed(LEFT, SHORT)" to
check if the left button was pushed for a short amount of
time (< 500 ms). In this case, the speed is reduced by 32
using "changeSpeed(-32)".
"buttonPressed(LEFT, LONG)": If the button is pressed for a
long time, "stepBack(15, 3)" is used to have the ant move
backward 15 steps on the left and 3 steps on the right.
This will result in a rotation of 12 steps to the left.
#include <VariAnt.h>
VariAnt ant;
void setup( )
{
ant.setup( );
ant.setSpeed(160);
}
void loop( )
{
ant.update( );
if(ant.buttonPressed(LEFT, SHORT))
ant.changeSpeed(-32);
if(ant.buttonPressed(RIGHT, SHORT))
ant.changeSpeed(32);
if(ant.buttonPressed(LEFT, LONG))
ant.stepBack(15, 3);
if(ant.buttonPressed(RIGHT, LONG))
ant.stepBack(3, 15);
}
Need help?
Do you have a question about the variAnt and is the answer not in the manual?