Boomerang Bot Improvements

HI everyone

So a while ago I used variables to get Sparki to explore an area and return to the home zone.

I decided to improve this code using functions, constant variables, and a better way for the Sparki to get more accurately into the home area.

Code below: let me know what you think 🙂

And if you follow this link, you can watch a video of the code being completed.

#include <Sparki.h> // include the sparki library 

const int response1 = random(1,3);

 const int response2 = random(45, 90);
 
 const int response3 = random(1,3); 

 const int response4 = random(45, 90);

 const int response5 = random(1, 3);
 
 const int response6 = random(45, 90);
 
 const int response7 = random(1, 3);
 
 const int home=(response1*10+3);
 
void setup()
{
 sparki.servo(0);
}
void loop()
{
 startingHomeZone();
 movingForward();
 movingBack();
 homeAdjust();
}
void startingHomeZone()
{
 delay(1000);
 sparki.beep();
 sparki.moveLeft(30);
 delay(1000);
 sparki.moveRight(30);
 sparki.clearLCD();
 sparki.println("home zone");
 sparki.updateLCD();
 delay(1000);
}

void movingForward()
{
 sparki.clearLCD();
 randomSeed(analogRead(1));
int response1 = random(1,3);
 sparki.clearLCD();
 sparki.print(response1);
 sparki.updateLCD();
 delay(1000);
 sparki.moveForward(response1 *10);
 sparki.clearLCD();
 randomSeed(analogRead(1));
 int response2 = random(45, 90);
 sparki.clearLCD();
 sparki.print(response2);
 sparki.updateLCD();
 delay(1000);
 sparki.moveLeft(response2);
 sparki.clearLCD();
 randomSeed(analogRead(1));
 int response3 = random(1,3);
 sparki.clearLCD();
 sparki.print(response3);
 sparki.updateLCD();
 delay(1000);
 sparki.moveForward(response3*10);
 sparki.clearLCD();
 randomSeed(analogRead(1));
 int response4 = random(45, 90);
 sparki.clearLCD();
 sparki.print(response4);
 sparki.updateLCD();
 delay(1000);
 sparki.moveRight(response4);
 sparki.clearLCD();
 randomSeed(analogRead(1));
 int response5 = random(1, 3);
 sparki.clearLCD();
 sparki.print(response5);
 sparki.updateLCD();
 delay(1000);
 sparki.moveForward(response5 *10);
 delay(1000);
 sparki.clearLCD();
 randomSeed(analogRead(1));
 int response6 = random(45, 90);
 sparki.clearLCD();
 sparki.print(response6);
 sparki.updateLCD();
 delay(1000);
 sparki.moveLeft(response6);
 sparki.clearLCD();
 randomSeed(analogRead(1));
 int response7 = random(1, 3);
 sparki.clearLCD();
 sparki.print(response7);
 sparki.updateLCD();
 delay(1000);
 sparki.moveForward(response7 *10);
 delay(1000);
}
 void movingBack()
{
 sparki.moveLeft(180);
 delay(1000);
 sparki.moveForward(response7 *10);
 delay(1000);
 sparki.moveRight(response6);
 delay(1000);
 sparki.moveForward(response5*10);
 delay(1000);
 sparki.moveLeft(response4);
 delay(1000);
 sparki.moveForward(response3*10);
 delay(1000);
 sparki.moveRight(response2);
 delay(1000);

}

void homeAdjust()
{
 int home=(response1*10+3);
 sparki.moveForward(home);
 sparki.moveLeft(180);
 delay(1000);
 sparki.moveForward(2);
 sparki.beep();
 sparki.clearLCD();
 sparki.drawString(10,1, "home");
 sparki.updateLCD();
 delay(100000);
}

 

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s