Entertainment Bot code and video part 1

So I worked on the entertainment bot idea and this is the first code that I came up with. As I am posting these codes in order that I worked on them, my current entertainment bot tweak will be posted in a few weeks time, as now I have a touch and a sound sensor which really helps ūüôā ūüôā

DSC_0047

The idea with this code was to program Sparki to act like a generic entertainment robot with silly dances, random movements, tune playing and following hand code.

This is the code:

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

void setup()
{
float lightLeft = 0;
float lightCenter = 0;
float lightRight = 0;
float threshold = 800;
float edgeLeft = 0;
float edgeRight = 0;
sparki.clearLCD(); // wipe the LCD clear
sparki.drawString(40, 4, "HELLO");
sparki.updateLCD(); // put the drawings on the screen
delay(1000);
sparki.moveLeft(30);
sparki.moveRight(30);
delay(1000);
sparki.beep(640, 200);
delay(200);
sparki.beep(440, 200);
delay(100);
while(true)
{
lightLeft = sparki.lightLeft();
lightCenter = sparki.lightCenter();
lightRight = sparki.lightRight();
edgeLeft = sparki.edgeLeft();
edgeRight = sparki.edgeRight();
sparki.servo(0);
sparki.RGB(0,220,0);
if(((lightCenter&gt;lightLeft)&amp;&amp;(lightRight&gt;lightLeft)))
{
delay(400);
sparki.beep(840, 300);
sparki.moveForward(3);
sparki.moveRight(40);
sparki.beep(440, 500);
sparki.RGB(0,250,0);
sparki.moveLeft(90);
sparki.moveForward(3);
sparki.beep(640, 200);
delay(200);
sparki.beep(740, 200);
sparki.moveBackward(3);
sparki.moveForward(5);
sparki.RGB(220,0,0);
sparki.beep(340, 400);
delay(200);
sparki.beep(640, 400);
sparki.moveRight(90);
sparki.moveBackward(5);
sparki.beep(540, 400);
sparki.RGB(0,0,220);
}
else
{
delay(1000);
}
if(((lightLeft&gt;lightRight)&amp;&amp;(lightCenter&gt;lightRight)))
{
delay(400);
sparki.beep(840, 400);
delay(200);
sparki.beep(640, 400);
delay(200);
sparki.beep(440, 400);
delay(200);
sparki.beep(340, 400);
delay(200);
sparki.beep(640, 800);
delay(200);
sparki.beep(440, 800);
delay(200);
sparki.beep(340, 400);
delay(200);
sparki.beep(440, 400);
delay(200);
sparki.beep(640, 400);
delay(200);
}
else
{
delay(1000);
}
if(((edgeLeft&lt;threshold)&amp;&amp;(sparki.ping()&gt;10)))
{
sparki.RGB(220,0,0);
sparki.beep(840, 400);
sparki.moveLeft(90);
sparki.beep(440, 200);
sparki.moveRight(90);
sparki.beep(340, 200);
delay(100);
sparki.beep(540, 200);
sparki.RGB(0,0,220);
sparki.beep(440, 400);
sparki.moveForward(5);
delay(200);
sparki.beep(640, 400);
delay(200);
sparki.beep(740, 500);
sparki.moveBackward(5);
delay(200);
}
else
{
}
if(((edgeRight&lt;threshold)&amp;&amp;(sparki.ping()&gt;10)))
{
sparki.beep(740, 600);
delay(400);
sparki.beep(540, 400);
delay(400);
sparki.beep(540, 200);
delay(200);
sparki.beep(440, 200);
delay(200);
sparki.beep(640, 400);
delay(400);
sparki.beep(740, 200);
delay(400);
sparki.beep(740, 200);
}
else
{
}
sparki.servo(0);
delay(1000);
if((sparki.ping()&lt;10))
{
sparki.moveForward(7);
sparki.servo(90);
delay(1000);
if((sparki.ping()&lt;10))
{
sparki.moveRight(90);
sparki.moveForward(7);
sparki.servo(-(90));
delay(1000);
if((sparki.ping()&lt;10))
{
sparki.moveLeft(90);
sparki.moveForward(7);
}
else
{
sparki.moveBackward(5);
sparki.RGB(0,0,220);
sparki.moveLeft(180);
}
}
else
{
sparki.servo(-(90));
delay(1000);
if((sparki.ping()&lt;10))
{
sparki.moveLeft(90);
sparki.moveForward(7);
}
else
{
}
}
}
else
{
sparki.servo(90);
delay(1000);
if((sparki.ping()&lt;10))
{
sparki.moveRight(90);
sparki.moveForward(7);
}
else
{
sparki.servo(-(90));
delay(1000);
if((sparki.ping()&lt;10))
{
sparki.moveLeft(90);
sparki.moveForward(7);
}
else
{
sparki.moveForward(5);
sparki.RGB(0,0,220);
sparki.moveRight(90);
sparki.moveLeft(90);
}
}
}
delay(1000);
}
}

void loop()
{
}

Here is a video of the code in action:

https://drive.google.com/file/d/0B6y9ITteBcqLR2FwNkoweU1pOVk/view?usp=sharing

Let me know what you think ūüôā ūüôā

Advertisements

2 thoughts on “Entertainment Bot code and video part 1

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