Sparki the desk cleaning robot

With this simple code Sparki simply wanders around the desk, avoiding edges and obstacles. By using a sponge between his grippers, he can now clean while he explores too!

#include // include the sparki library
void setup()
{
}
void loop()
{
sparki.clearLCD();
sparki.drawString(10,1,"Hello human");
freeRoam();
}
void freeRoam(){
sparki.clearLCD();
sparki.drawString(10,1, "I'm exploring");
sparki.updateLCD();
delay(1000);
for (int i = 0; i < 60; i=i+1)
{
int edgeLeft = sparki.edgeLeft(); // measure the left edge IR sensor
int edgeRight = sparki.edgeRight(); // measure the right edge IR sensor
int threshold = 200; // if below this value, no surface underneath
if (edgeLeft < threshold) // if no surface underneath left sensor
{
sparki.moveBackward(4);
sparki.moveLeft(90); // turn right
}
if (edgeRight < threshold) // if no surface underneath right sensor
{
sparki.moveBackward(4);
sparki.moveLeft(90); // turn left
}
if (sparki.ping() < 5) {
sparki.moveStop();
sparki.moveLeft(90);
}
else{
sparki.moveForward(); // move forward
delay(100); // wait 0.1 seconds
}
}
sparki.moveStop();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s