Sparki Magic Eight Ball

More work with the accelerometer. Shake Sparki to reveal the answers to your darkest, deepest questions. Yep, Sparki is a magic eight ball! This can literally have endless answers, but I only used 4 in this example. Here is the code:


#include // include the sparki library
void setup()
{
}
void loop() {
sparki.clearLCD();
sparki.drawString(10,1,"Hello human");
sparki.drawString(10,3,"Shake me to answer all");
sparki.drawString(10,5,"your questions");
sparki.updateLCD();
delay(5000);
float x = sparki.accelX();
float y = sparki.accelY();
float z = sparki.accelZ();
if ((y>2)||(y<=-2))
{
randomSeed(analogRead(1));
int response1 = random(1,4);
if (response1==1)
{
sparki.beep(440,100);
delay(500);
sparki.beep(440,100);
sparki.RGB(100,0,0);
sparki.clearLCD();
sparki.drawString(10,1,"Absolutely not!");
sparki.updateLCD();
delay(2000);
}
else if(response1==2)
{
sparki.beep(240,100);
delay(500);
sparki.beep(240,100);
sparki.RGB(0,100,0);
sparki.clearLCD();
sparki.drawString(10,1,"Always!");
sparki.updateLCD();
delay(2000);
}
else if(response1==3)
{
sparki.beep(640,100);
delay(500);
sparki.beep(640,100);
sparki.RGB(0,0,100);
sparki.clearLCD();
sparki.drawString(10,1,"It's possible");
sparki.updateLCD();
delay(2000);
}
else
{
sparki.beep(640,100);
delay(500);
sparki.beep(640,100);
sparki.RGB(0,0,100);
sparki.clearLCD();
sparki.drawString(10,1,"Maybe...");
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