Sparki the Timer Robot – improvements

So in this code I aimed to build on my Sparki the Timer Robot code to allow the user to switch off both the five minute alarm and the ten minute alarm whilst it is sounding. This made it more user friendly and less annoying!

DSC_0395

Here is a link to the video:

Find below the code, let me know what you think 🙂

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

void setup() {
 sparki.RGB(RGB_OFF);
 sparki.servo(60);
}
void loop()
{
 sparki.beep(640, 400);
 delay(500);
 sparki.beep(340,400);
 delay(500);
 sparki.clearLCD();
 sparki.drawString(10,2, "Hello");
 sparki.updateLCD();
 delay (5000);
 sparki.clearLCD();
 sparki.drawString(10,2, "Would you like to set an alarm?");
 sparki.updateLCD();
 delay (5000);
 int left = sparki.lightLeft();
 int right = sparki.lightRight();
 if (left>=right)
 {
 sparki.clearLCD();
 sparki.drawString(10,2, "Choose Right for five minutes");
 sparki.updateLCD();
 delay (5000);
 sparki.clearLCD();
 sparki.drawString(10,2, "Choose Left for ten minutes");
 sparki.updateLCD();
 delay (5000);
 sparki.clearLCD();
 sparki.drawString(10,2, "Right (5) or Left (10)");
 sparki.updateLCD();
 delay (5000);
 int left = sparki.lightLeft();
 int right = sparki.lightRight();
 if (left>=right)
 {
 sparki.clearLCD();
 sparki.drawString(10,2, "5 minute alarm set");
 sparki.updateLCD();
 delay (3000);
 for (int i = 0; i < 3; i=i+1)
 {
 delay (100000);
 sparki.moveLeft(30);
 sparki.moveRight(30);
 }
 sparki.clearLCD();
 sparki.drawString(10,2, "Alarm time reached");
 sparki.updateLCD();
 delay (5000);
 sparki.ping();
 while (sparki.ping()>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);
 }
 sparki.clearLCD();
 sparki.drawString(10,2, "Alarm off");
 sparki.updateLCD();
 delay(100000);
}
 
 
 if (left<right)
 {
 sparki.clearLCD();
 sparki.drawString(10,2, "10 minute alarm set");
 sparki.updateLCD();
 delay (5000);
 for (int i = 0; i < 6; i=i+1)
 {
 delay (100000);
 sparki.moveLeft(30);
 sparki.moveRight(30);
 }
 sparki.clearLCD();
 sparki.drawString(10,2, "Alarm time reached");
 sparki.updateLCD();
 delay (5000);
 while (sparki.ping()>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);
 }
 sparki.clearLCD();
 sparki.drawString(10,2, "Alarm off");
 sparki.updateLCD();
 delay(100000);
}
 }
 
 sparki.clearLCD();
 sparki.drawString(10,2, "Ok maybe later");
 sparki.updateLCD();
 delay (5000);
 sparki.beep(450,400);
 delay(500);
 sparki.beep(750,400);
delay(500);
delay (100000);
}


Advertisements

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