Relay Race


#1

So for an event at our FE college we set up a relay race for 2 Sparki’s using two separate codes entered onto two separate Sparki’s. Here is a video:https://drive.google.com/file/d/0B6y9ITteBcqLWENmRlBNeW5zSk0/view?usp=sharing

We kept it nice and basic, here is the code:


//THE FIRST ROBOT

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

void setup() {
 sparki.servo(0);
 sparki.clearLCD();
 sparki.println("1st Sparki");
 sparki.updateLCD();
 delay(1000);
 findWall();
 avoidWall();
 findWall();
 avoidWall();
 findRobot();
 delay(100000);
}
void findWall()
{
 sparki.ping();
delay(1000);
while (sparki.ping()>10)
{
 sparki.moveForward();
delay(200);
}
}
void avoidWall()
{
 sparki.ping();
delay(1000);
if (sparki.ping()<20)
{
 sparki.moveRight(90);
}
}
void findRobot()
{
 sparki.ping();
 delay(1000);
 while (sparki.ping()>8)
 {
 sparki.moveForward(5);
 sparki.ping();
 delay(1000);
 if (sparki.ping()<=8)
 {
 sparki.servo(0);
 sparki.clearLCD();
 sparki.println("Found 2nd Sparki");
 sparki.updateLCD();
 delay(1000);
sparki.beep();
sparki.gripperClose(10);
delay(1000);
sparki.gripperOpen(10);
delay(1000);
sparki.gripperStop();
sparki.moveStop();
delay(100000);
}
}
}
void loop() {
 // put your main code here, to run repeatedly:

}

//THE SECOND ROBOT

#include <Sparki.h> // include the sparki library
void setup()
{}
void loop() {

 sparki.servo(0);
 sparki.clearLCD();
 sparki.println("2nd Sparki");
 sparki.updateLCD();
 delay(1000);
 sparki.ping();
delay(1000);
if (sparki.ping()<20)
{
 delay (10000);
sparki.beep();
sparki.moveBackward(10);
sparki.moveLeft(180);
 
 findWall();
 avoidWall();
 findTheFinishLine();
 delay(100000);
}
delay(1000);
}

void findWall()
{
 sparki.ping();
delay(1000);
while (sparki.ping()>10)
{
 sparki.moveForward();
delay(200);
}
}
void avoidWall()
{
 sparki.ping();
delay(1000);
if (sparki.ping()<20)
{
 sparki.moveRight(90);
}
}
void findTheFinishLine()
{
 sparki.ping();
delay(1000);
while (sparki.ping()>10)
{
 sparki.moveForward(5);
}
int lineLeft = sparki.lineLeft(); 
int lineRight = sparki.lineRight(); 
sparki.clearLCD();
sparki.println(lineLeft);
sparki.updateLCD();
delay(1000);
sparki.clearLCD();
sparki.println(lineRight);
sparki.updateLCD();
delay(1000);
if ((lineLeft<600) && (lineRight<600))
{
sparki.beep();
sparki.RGB(0,250,0);
sparki.clearLCD();
sparki.println("complete");
sparki.updateLCD();
delay(3000);
}
}