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);
 }
 }
 }

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s