Accelerometer music

Using the Arcbotics Sparki lesson to learn about the accelerometer, and I made my own version:


#include // include the sparki library
void setup()
{
}
void loop() {
sparki.clearLCD();
float x = sparki.accelX();
float y = sparki.accelY();
float z = sparki.accelZ();
sparki.print("Accel X: ");
sparki.println(x);
sparki.print("Accel Y: ");
sparki.println(y);
sparki.print("Accel Z: ");
sparki.println(z);
sparki.updateLCD();
if (y>=5)
{
sparki.beep(540,100);
delay(500);
}
if ((y<5)&&(y>=0))
{
sparki.beep(440,100);
delay(500);
}
if((y<0)&&(y>=-3))
{
sparki.beep(340,100);
delay(500);
}
if (y<-3)
{
sparki.beep(240,100);
delay(500);
}
}

Advertisements

Sparki accelerometer shake game

So one of the things I haven’t really explored with Sparki is the accelerometer. But as I recently got my hands on a Sphero Mini, I’ve been enjoying learning about this sensor.

So the accelerometer works on a 3 axis sensor. X, Y and Z.  X measures the left/right acceleration, Y measures the forward/backward acceleration, and Z measures the up/down acceleration.

Here is a little game I made using the data from the X sensor:

 sparki.clearLCD();
 sparki.drawString(10,1,"Hello human");
 sparki.drawString(10,3,"shake me when you see the");
 sparki.drawString(10,5,"GREEN LIGHT");
 sparki.updateLCD();
 delay(5000);
 int score=0;
 int counter1=0;
 while (counter1<10)
 {
 randomSeed(analogRead(1));
 int response1 = random(1,4);
 int counter=0;
 while(counter<response1)
 {
 sparki.RGB(100,0,0); // Make the LED maximum Red
 delay(1000);
 sparki.RGB(0,0,100); // Make the LED maximum Blue
 delay(1000);
 counter=counter+1;
 }
 sparki.RGB(0,100,0); // Make the LED maximum Green
 delay(1000);
 if(sparki.accelX() <0)
 {
 score=score+1;
 sparki.clearLCD();
sparki.print(score);
sparki.updateLCD();
delay(1000);
 }
 counter1=counter1+1;
 }
 sparki.RGB(RGB_OFF); 
 sparki.clearLCD();
 sparki.drawString(10,1,"Well done!");
 sparki.drawString(10,3,"You scored");
 sparki.updateLCD();
 delay(1000);
 sparki.clearLCD();
sparki.print(score);
sparki.updateLCD();
delay(1000);
 
delay(10000);
}

Here is a link to a video of the code in action: https://www.youtube.com/watch?v=a2HxYJC1TaQ

Free roam or boomerang

In this code, you can use the light sensors to tell Sparki what you want him to do. He can either, free roam in your room or a given area, avoiding obstacles, or use the boomerang routine, where he will explore the zone and return to the “home” area.

Handy to have a robot wandering around. Might attach a cloth so he can buff the floor as he goes 🙂

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

 void loop()
 {
    sparki.clearLCD();
  sparki.drawString(10,1,"Hello human");
  sparki.drawString(10,3,"right for free roam");
  sparki.drawString(10,5,"left for boomerang");
  sparki.updateLCD();
  delay(5000);
  if (sparki.lightRight()>sparki.lightLeft())
  {
    boomerang();
  }
  else if (sparki.lightRight()<sparki.lightLeft())
  {
   for (int i = 0; i < 10; i=i+1)   {     freeRoam();   }   }   else{     delay(5000);      }  }    void freeRoam(){   while(sparki.ping()>10)
      {
      sparki.moveForward();
      sparki.servo(0);
                    }
                        sparki.moveStop();
                          sparki.servo(90);
                          delay(1000);
                          int R=sparki.ping();
                          sparki.ping();
                          delay(2000);
                          sparki.clearLCD();
                          sparki.println(R);
                          sparki.updateLCD();
                          delay(1000);
                          sparki.servo(-90);
                          delay(1000);
                          int L = sparki.ping();
                          sparki.ping();
                          delay(2000);
                          sparki.clearLCD();
                          sparki.println(L);
                          sparki.updateLCD();
                          delay(1000);
                          sparki.servo(0);
                          if((R>10) && (R>=L))
                          {
                          sparki.moveRight(90);
                          sparki.servo(0);
                          }
                          if ((L>10) && (L>=R))
                          {
                            sparki.moveLeft(90);
                            sparki.servo(0);
                          }
                         if ((R<=10) && (L <= 10))
                         {
                           sparki.moveRight(180);
                           sparki.RGB(0,0,220);
                           sparki.servo(0);
                         }
}

void boomerang()
{
   sparki.beep();
  sparki.moveLeft(30);
  sparki.moveRight(30);
  sparki.clearLCD();
  sparki.println("home zone");
  sparki.updateLCD();
  delay(1000);
   sparki.clearLCD();
  randomSeed(analogRead(1));
int response1 = random(1,3);
  sparki.clearLCD();
  sparki.print(response1);
  sparki.updateLCD();
  sparki.moveForward(response1 *10);
  sparki.clearLCD();
  randomSeed(analogRead(1));
  int response2 = random(45, 90);
  sparki.clearLCD();
  sparki.print(response2);
  sparki.updateLCD();
  sparki.moveLeft(response2);
  sparki.clearLCD();
  randomSeed(analogRead(1));
  int response3 = random(1,3);
  sparki.clearLCD();
  sparki.print(response3);
  sparki.updateLCD();
  sparki.moveForward(response3*10);
  sparki.clearLCD();
  randomSeed(analogRead(1));
  int response4 = random(45, 90);
  sparki.clearLCD();
  sparki.print(response4);
  sparki.updateLCD();
  sparki.moveRight(response4);
  sparki.clearLCD();
  randomSeed(analogRead(1));
  int response5 = random(1, 3);
  sparki.clearLCD();
  sparki.print(response5);
  sparki.updateLCD();
   sparki.moveForward(response5 *10);
    sparki.clearLCD();
  randomSeed(analogRead(1));
  int response6 = random(45, 90);
  sparki.clearLCD();
  sparki.print(response6);
  sparki.updateLCD();
  sparki.moveLeft(response6);
  sparki.clearLCD();
  randomSeed(analogRead(1));
  int response7 = random(1, 3);
  sparki.clearLCD();
  sparki.print(response7);
  sparki.updateLCD();
   sparki.moveForward(response7 *10);
    sparki.moveLeft(180);
    sparki.moveForward(response7 *10);
    sparki.moveRight(response6);
  sparki.moveForward(response5*10);
  sparki.moveLeft(response4);
  sparki.moveForward(response3*10);
  sparki.moveRight(response2);
int home=(response1*10+3);
  sparki.moveForward(home);
  sparki.moveLeft(180);
  sparki.moveForward(2);
  sparki.beep();
  sparki.clearLCD();
  sparki.drawString(10,1, "home");
  sparki.updateLCD();
  delay(1000);
}

 

Much improved rock, paper, scissors

Follow the instructions on the LCD screen. Use a torch to make your choice between rock, paper and scissors. This could easily be replicated with any LCD screen and 3 light sensors.

In this version, Sparki will also keep score. Although this will be displayed in the very top left hand corner instead of the middle of the screen as you would expect. This is because I haven’t yet learnt how to convert a variable of an integer value into a string to be displayed using the drawString(co-ordinates) command.

Here is the code:

#include // include the sparki library
int player = 0;
int robot = 0;
void setup() {
}
void rock()
{
sparki.RGB(RGB_RED);
sparki.beep(340, 400);
delay(150);
sparki.beep(640, 800);
delay(150);
sparki.clearLCD();
sparki.drawString(20, 2, "You choose ROCK");
sparki.updateLCD();
delay(1000);
sparki.RGB(RGB_OFF);
randomSeed(analogRead(1));
int response2b = random(1, 30);
if (response2b < 10)
{
rockChoice();
draw();
hum();
}
if ((response2b < 20) && (response2b > 10))
{
paperChoice();
win();
dance();
}
if (response2b > 20)
{ scissorsChoice();
lose();
dance2();
}
}
void paper()
{
sparki.RGB(RGB_ORANGE);
sparki.beep(340, 400);
delay(150);
sparki.beep(340, 400);
delay(150);
sparki.clearLCD();
sparki.drawString(20, 2, " You choose PAPER");
sparki.updateLCD();
delay(1000);
sparki.RGB(RGB_OFF);
randomSeed(analogRead(1));
int response2b = random(1, 30);
if (response2b < 10)
{
rockChoice();
lose();
dance2();
}
if ((response2b < 20) && (response2b > 10))
{
paperChoice();
draw();
hum();
}
if (response2b > 20)
{
scissorsChoice();
win();
dance();
}
}
void scissors()
{
sparki.RGB(RGB_YELLOW);
sparki.beep(640, 400);
delay(150);
sparki.beep(340, 800);
delay(150);
sparki.clearLCD();
sparki.drawString(20, 2, "You choose");
sparki.drawString(20, 4, "SCISSORS");
sparki.updateLCD();
delay(1000);
sparki.RGB(RGB_OFF);
randomSeed(analogRead(1));
int response2b = random(1, 30);
if (response2b < 10)
{
rockChoice();
win();
dance();
}
if ((response2b < 20) && (response2b > 10))
{
paperChoice();
lose();
dance2();
}
if (response2b > 20)
{
scissorsChoice();
draw();
hum();
}
}
void dance()
{
sparki.moveForward(3);
sparki.beep(840, 400);
delay(150);
sparki.beep(640, 400);
delay(150);
sparki.beep(440, 400);
delay(150);
sparki.moveBackward(3);
}
void dance2()
{
sparki.moveLeft(10);
sparki.beep(340, 400);
delay(150);
sparki.beep(640, 800);
delay(150);
sparki.beep(440, 800);
delay(150);
sparki.moveRight(10);
}
void hum()
{
sparki.beep(340, 400);
delay(150);
sparki.beep(440, 400);
delay(150);
sparki.beep(640, 400);
}
void rockChoice()
{
sparki.clearLCD();
sparki.drawString(20, 2, "I choose ROCK");
sparki.updateLCD();
delay(1000);
}
void paperChoice()
{
sparki.clearLCD();
sparki.drawString(20, 2, " I choose PAPER");
sparki.updateLCD();
delay(1000);
}
void scissorsChoice()
{
sparki.clearLCD();
sparki.drawString(20, 2, "I choose");
sparki.drawString(20, 4, "SCISSORS");
sparki.updateLCD();
delay(1000);
}
void win()
{
sparki.clearLCD();
sparki.drawString(20, 2, "I won");
sparki.updateLCD();
delay(1000);
robot = robot + 1;
dance();
}
void lose()
{
sparki.clearLCD();
sparki.drawString(20, 2, "You won");
sparki.updateLCD();
delay(1000);
player = player + 1;
dance2();
}
void draw()
{
sparki.clearLCD();
sparki.drawString(20, 2, "It was a draw");
sparki.updateLCD();
delay(1000);
hum();
}
void loop()
{
sparki.clearLCD();
sparki.drawString(20, 2, "Let's play");
sparki.drawString(10, 5, "Rock Paper Scissors");
sparki.updateLCD();
delay(3000);
sparki.RGB(RGB_RED);
delay(200);
sparki.RGB(RGB_ORANGE);
delay(200);
sparki.RGB(RGB_YELLOW);
delay(200);
for (int i = 0; i < 3; i = i + 1) { sparki.clearLCD(); sparki.drawString(20, 1, "RIGHT = ROCK"); sparki.drawString(18, 4, "CENTER = SCISSORS"); sparki.drawString(20, 7, "LEFT = PAPER"); sparki.updateLCD(); delay(8000); if ((sparki.lightRight() > sparki.lightLeft()) && (sparki.lightRight() > sparki.lightCenter()))
{
rock();
}
else if ((sparki.lightRight() < sparki.lightLeft()) && (sparki.lightLeft() > sparki.lightCenter()))
{
paper();
}
else if ((sparki.lightCenter() > sparki.lightRight()) && (sparki.lightCenter() > sparki.lightLeft()))
{
scissors();
}
sparki.clearLCD();
sparki.drawString(20, 2, "You scored");
sparki.updateLCD();
delay(1000);
sparki.clearLCD();
sparki.print(player);
sparki.updateLCD();
delay(1000);
sparki.clearLCD();
sparki.drawString(20, 2, "I scored");
sparki.updateLCD();
delay(1000);
sparki.clearLCD();
sparki.print(robot);
sparki.updateLCD();
delay(1000);
}
if (player > robot)
{
sparki.clearLCD();
sparki.drawString(20, 2, "Well done!");
sparki.updateLCD();
delay(1000);
}
else if (player < robot)
{
sparki.clearLCD();
sparki.drawString(20, 2, "Yey I won!");
sparki.updateLCD();
delay(1000);
}
else
{
draw();
}
delay(10000);
}

Simon Says (LCD screen, 2 light sensors and a Ultra-sonic sensor)

I made a really quick Simon Says or (just Simon) with Sparki. All it uses is the screen, the two light sensors and the ultra-sonic sensor 🙂 It’s not all that impressive but it’s fun for little ones 🙂

Here is the code:

#include // include the sparki library
 void setup() {
 sparki.servo(60);
 }
 void loop()
 {
 sparki.clearLCD();
 sparki.servo(60);
 sparki.ping();
 if(sparki.ping()<10)
 {
 sparki.moveForward(3);
 sparki.moveBackward(3);
 sparki.drawString(10, 2, "Hello Human");
 sparki.updateLCD();
 delay(2000);
 sparki.clearLCD();
 sparki.drawString(20, 2, "Let's play");
 sparki.drawString(10, 5, "Simon says");
 sparki.updateLCD();
 delay(2000);
 sparki.clearLCD();
 sparki.drawString(20, 2, "RIGHT for yes");
 sparki.drawString(20, 5, "LEFT for no");
 sparki.updateLCD();
 delay(5000);
 if (sparki.lightRight() < sparki.lightLeft())
 {
 delay(2000);
 sparki.RGB(RGB_RED);
 delay(200);
 sparki.RGB(RGB_ORANGE);
 delay(200);
 sparki.RGB(RGB_YELLOW);
 delay(200);
 sparki.clearLCD();
 sparki.drawString(20, 2, "Ok then");
 sparki.drawString(20, 5, "Let's play");
 sparki.updateLCD();
 delay(5000);
 for (int i = 0; i < 5; i=i+1)
 {
 simon();
 }
 sparki.clearLCD();
 sparki.drawString(20, 2, "That was fun!");
 sparki.updateLCD();
 delay(15000);
 }}
 delay(10000);
 }
 void simon()
 {
 randomSeed(analogRead(1));
 int response2b = random(1, 30);
 if (response2b < 5) { sparki.clearLCD(); sparki.drawString(20, 2, "Simon Says"); sparki.updateLCD(); delay(1000); sparki.clearLCD(); sparki.drawString(20, 2, "press LEFT"); sparki.updateLCD(); delay(4000); if (sparki.lightRight() > sparki.lightLeft())
 {
 sparki.clearLCD();
 sparki.drawString(20, 2, "well done!");
 sparki.updateLCD();
 delay(2000);
 }
 else
 {
 sparki.clearLCD();
 sparki.drawString(20, 2, "Too late!");
 sparki.updateLCD();
 delay(2000);
 }}

if ((response2b < 10) && (response2b > 5))
 {
 sparki.clearLCD();
 sparki.drawString(20, 2,"Simon Says");
 sparki.updateLCD();
 delay(1000);
 sparki.clearLCD();
 sparki.drawString(20, 2, "Press RIGHT");
 sparki.updateLCD();
 delay(2000);
 if (sparki.lightRight() < sparki.lightLeft())
 {
 sparki.clearLCD();
 sparki.drawString(20, 2, "well done!");
 sparki.updateLCD();
 delay(2000);
 }
 else
 {
 sparki.clearLCD();
 sparki.drawString(20, 2, "Too late!");
 sparki.updateLCD();
 delay(2000);
 }}

if ((response2b < 15) && (response2b > 10))
 { sparki.clearLCD();
 sparki.drawString(20, 2,"Simon says");
 sparki.updateLCD();
 delay(1000);
 sparki.clearLCD();
 sparki.drawString(20, 2, "wave");
 sparki.updateLCD();
 delay(2000);
 sparki.servo(60);
 sparki.ping();
 if(sparki.ping()<10)
 {
 sparki.clearLCD();
 sparki.drawString(20, 2, "Well Done!");
 sparki.updateLCD();
 delay(2000);
 }
 else
 {
 sparki.clearLCD();
 sparki.drawString(20, 2, "Too slow");
 sparki.updateLCD();
 delay(2000);
 }
 }
 if ((response2b < 20) && (response2b > 15))
 {
 sparki.clearLCD();
 sparki.drawString(20, 2, "You should");
 sparki.updateLCD();
 delay(1000);
 sparki.clearLCD();
 sparki.drawString(20, 2, "press LEFT");
 sparki.updateLCD();
 delay(4000);
 if (sparki.lightRight() > sparki.lightLeft())
 {
 sparki.clearLCD();
 sparki.drawString(20, 2, "Haha I win");
 sparki.updateLCD();
 delay(2000);
 }
 else
 {
 sparki.clearLCD();
 sparki.drawString(20, 2, "Well done");
 sparki.updateLCD();
 delay(2000);
 }}

if ((response2b < 25) && (response2b > 20))
 {
 sparki.clearLCD();
 sparki.drawString(20, 2,"Why not");
 sparki.updateLCD();
 delay(1000);
 sparki.clearLCD();
 sparki.drawString(20, 2, "Press RIGHT");
 sparki.updateLCD();
 delay(2000);
 if (sparki.lightRight() < sparki.lightLeft()) { sparki.clearLCD(); sparki.drawString(20, 2, "Haha I win"); sparki.updateLCD(); delay(2000); } else { sparki.clearLCD(); sparki.drawString(20, 2, "Well done"); sparki.updateLCD(); delay(2000); } } if (response2b > 25)
 { sparki.clearLCD();
 sparki.drawString(20, 2,"You should");
 sparki.updateLCD();
 delay(1000);
 sparki.clearLCD();
 sparki.drawString(20, 2, "wave");
 sparki.updateLCD();
 delay(2000);
 sparki.servo(60);
 sparki.ping();
 if(sparki.ping()<10)
 {
 sparki.clearLCD();
 sparki.drawString(20, 2, "Haha I won");
 sparki.updateLCD();
 delay(2000);
 }
 else
 {
 sparki.clearLCD();
 sparki.drawString(20, 2, "Well done");
 sparki.updateLCD();
 delay(2000);
 }
 }
 }
arcbotics sparki

Jingle Bells

Sparki get festive! Here is the code to make Sparki “sing” his very own rendition of jingle bells using the piezo buzzer:

#include
void setup(){
sparki.servo(60);
sparki.RGB(RGB_RED);
sparki.clearLCD();
delay(2000);
sparki.drawString(10,2,"Merry");
sparki.drawString(10,4,"Christmas");
sparki.updateLCD();
delay(2000);
}
void loop(){
sparki.moveLeft(30);
sparki.moveRight(30);
for (int i = 0; i < 2; i=i+1)
{
sparki.beep(400, 250);
delay(330);//jin
sparki.beep(400, 250);
delay(330);//gle
sparki.beep(400, 450);
delay(530);//bells
sparki.beep(400, 250);
delay(330);//jin
sparki.beep(400, 250);
delay(330);//gle
sparki.beep(400, 450);
delay(530);//bells
sparki.beep(400, 250);
delay(330);//jin
sparki.beep(600, 250);
delay(330);//gle
sparki.beep(300, 450);
delay(530);//all
sparki.beep(400, 150);
delay(230);//the
sparki.beep(400, 700);
delay(1020);//way
//second line
sparki.beep(500, 250);
delay(330);//oh
sparki.beep(500, 250);
delay(330);//what
sparki.beep(500, 250);
delay(330);//fun
sparki.beep(500, 150);
delay(230);//it
sparki.beep(500, 150);
delay(230);//is
sparki.beep(400, 250);
delay(330);//to
sparki.beep(400, 250);
delay(430);//ride
sparki.beep(400, 150);
delay(230);//in
sparki.beep(400, 150);
delay(230);//a
sparki.beep(400, 250);
delay(330);//one
sparki.beep(300, 250);
delay(330);//horse
sparki.beep(300, 250);
delay(330);//ohhh
sparki.beep(400, 250);
delay(330);//pen
sparki.beep(300, 700);
delay(1020);//sleigh
sparki.beep(800, 700);
delay(1020);//hey
}
delay(100000);
}

And here is a link to the video!

Rock, Paper, Scissors

Inspired by Google Home and it’s ability to play rock, paper, scissors, I decided I’d quite like to play this with Sparki 🙂 after all, he is my favourite robot buddy! So here is the code for 5 rounds of rock, paper, scissors before a break, then he’ll ask you if you’d like to play again. Unfortunately, I haven’t wrapped my head around keeping score, I keep doing something wrong with my variables and they wont update with each round. So I just left it without scorekeeping for now.

#include &lt;Sparki.h&gt; // include the sparki library

void setup() {
  sparki.servo(60);
}

void loop()
{
  sparki.clearLCD();
  sparki.servo(60);
  sparki.ping();
  if(sparki.ping()&lt;10)
  {
    sparki.moveForward(3);
    sparki.moveBackward(3);
  sparki.drawString(10, 2, "Hello Human");
  sparki.updateLCD();
  delay(2000);
  sparki.clearLCD();
  sparki.drawString(20, 2, "Let's play");
  sparki.drawString(10, 5, "rock paper scissors");
  sparki.updateLCD();
  delay(2000);
  sparki.clearLCD();
  sparki.drawString(20, 2, "Choose RIGHT for yes");
  sparki.drawString(20, 5, "and LEFT for no");
  sparki.updateLCD();
  delay(5000);
  if (sparki.lightRight() &lt; sparki.lightLeft())
  {
    delay(2000);
    sparki.RGB(RGB_RED);
    delay(200);
    sparki.RGB(RGB_ORANGE);
    delay(200);
    sparki.RGB(RGB_YELLOW);
    delay(200);
    for (int i = 0; i &lt; 5; i=i+1)
    {
    sparki.drawString(20, 2, "Choose RIGHT for ROCK");
    sparki.drawString(16, 5, "Choose LEFT for PAPER");
    sparki.drawString(16, 8, "Choose CENTER for SCISSORS");
    sparki.updateLCD();
    delay(5000);
    if ((sparki.lightRight() &lt; sparki.lightLeft()) &amp;&amp; (sparki.lightRight() &lt; sparki.lightCenter()))
    {
      rock();
    }
    else if ((sparki.lightRight() &gt; sparki.lightLeft()) &amp;&amp; (sparki.lightLeft() &lt; sparki.lightCenter()))
    {
      paper();
    }
    else
    {
      scissors();

    }
  }

}}
delay(10000);
}

void rock()
{
  sparki.RGB(RGB_RED);
  sparki.clearLCD();
  sparki.drawString(20, 2,"You choose ROCK");
  sparki.updateLCD();
  delay(2000);
  sparki.RGB(RGB_OFF);
  sparki.clearLCD();
  sparki.drawString(10, 1, "This is my choice");
  sparki.updateLCD();
  delay(1000);
  randomSeed(analogRead(1));
  int response2b = random(1, 30);

  if (response2b &lt; 10)
  {
    sparki.clearLCD();
    sparki.drawString(20, 2, "I choose ROCK");
    sparki.updateLCD();
    delay(1000);
    sparki.clearLCD();
    sparki.drawString(20, 2, "It was a draw!");
    sparki.updateLCD();
    delay(2000);
    hum();
  }
  if ((response2b &lt; 20) &amp;&amp; (response2b &gt; 10))
  {
    sparki.clearLCD();
     sparki.drawString(20, 2,"I choose PAPER");
    sparki.updateLCD();
    delay(1000);
    sparki.clearLCD();
    sparki.drawString(20, 2, "Yey I won");
    sparki.updateLCD();
    delay(2000);
    dance();
  }
  if (response2b &gt; 20)
  { sparki.clearLCD();
     sparki.drawString(20, 2,"I choose SCISSORS");
    sparki.updateLCD();
    delay(1000);
    sparki.clearLCD();
    sparki.drawString(20, 2, "You won");
    sparki.updateLCD();
    delay(2000);
    dance2();
  }
}
void paper()
{
  sparki.RGB(RGB_ORANGE);
  sparki.clearLCD();
   sparki.drawString(20, 2," You choose PAPER");
  sparki.updateLCD();
  delay(2000);
  sparki.RGB(RGB_OFF);
  sparki.clearLCD();
  sparki.drawString(10, 1, "This is my choice");
  sparki.updateLCD();
  delay(1000);
  randomSeed(analogRead(1));
  int response2b = random(1, 30);

  if (response2b &lt; 10)
  {
    sparki.clearLCD();
     sparki.drawString(20, 2," I choose ROCK");
    sparki.updateLCD();
    delay(1000);
    sparki.clearLCD();
    sparki.drawString(20, 2, "You won");
    sparki.updateLCD();
    delay(2000);
    dance2();
  }
  if ((response2b &lt; 20) &amp;&amp; (response2b &gt; 10))
  {
    sparki.clearLCD();
    sparki.drawString(20, 2," I choose PAPER");
    sparki.updateLCD();
    delay(1000);
    sparki.clearLCD();
    sparki.drawString(20, 2, "It was a draw");
    sparki.updateLCD();
    delay(2000);
    hum();
  }
  if (response2b &gt; 20)
  { sparki.clearLCD();
    sparki.drawString(20, 2," I choose SCISSORS");
    sparki.updateLCD();
    delay(1000);
    sparki.clearLCD();
    sparki.drawString(20, 2, "I win");
    sparki.updateLCD();
    delay(2000);
    dance();
  }
}
void scissors()
{
  sparki.RGB(RGB_YELLOW);
  sparki.clearLCD();
  sparki.drawString(20, 2,"You choose");
  sparki.drawString(20, 4,"SCISSORS");
  sparki.updateLCD();
  delay(2000);
sparki.RGB(RGB_OFF);
  sparki.clearLCD();
  sparki.drawString(10, 1, "This is my choice");
  sparki.updateLCD();
  delay(1000);
  randomSeed(analogRead(1));
  int response2b = random(1, 30);

  if (response2b &lt; 10)
  {
    sparki.clearLCD();
    sparki.drawString(20, 2,"I choose ROCK");
    sparki.updateLCD();
    delay(1000);
    sparki.clearLCD();
    sparki.drawString(20, 2, "I won");
    sparki.updateLCD();
    delay(2000);
    dance();
  }
  if ((response2b &lt; 20) &amp;&amp; (response2b &gt; 10))
  {
    sparki.clearLCD();
    sparki.drawString(20, 2," I choose PAPER");
    sparki.updateLCD();
    delay(1000);
    sparki.clearLCD();
    sparki.drawString(20, 2, "You won");
    sparki.updateLCD();
    delay(2000);
    dance2();
  }
  if (response2b &gt; 20)
  { sparki.clearLCD();
    sparki.drawString(20, 2,"I choose");
    sparki.drawString(20, 4,"SCISSORS");
    sparki.updateLCD();
    delay(1000);
    sparki.clearLCD();
    sparki.drawString(20, 2, "It was a draw");
    sparki.updateLCD();
    delay(2000);
    hum();
  }
}

void dance()
{
 sparki.moveForward(3);
 sparki.beep(840, 400);
 delay(150);
 sparki.beep(640, 400);
 delay(150);
 sparki.beep(440, 400);
 delay(150);
 sparki.moveBackward(3);
}
void dance2()
{
  sparki.moveLeft(10);
 sparki.beep(340, 400);
 delay(150);
 sparki.beep(640, 800);
 delay(150);
 sparki.beep(440, 800);
 delay(150);
 sparki.moveRight(10);
}
void hum()
{
  sparki.beep(340, 400);
  delay(150);
 sparki.beep(440, 400);
 delay(150);
 sparki.beep(640, 400);
}