Returning to Home zone


#1

Using randomseed to set variables, Sparki can return to the location he started from, after wandering around an area (clear of obstacles), with you as the programmer not knowing where Sparki will go:

[code]#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);
}[/code]