Sparki the Timer Robot-Even more improvements

Hey Everyone

So you are probably sick to death of hearing about the timer robot code but I’m just trying to perfect it….

DSC_0350.JPG

Anyway, the one problem I had with the previous code was that once you had used the robot to set a timer it became a little long winded upon using it again, to be given instructions each time and to have to scroll through all of the options to get to the latest ones.

To fix this, I decided to add in an option at the start of the code where you could tell the robot if you had used the program before. If yes, the quick options function is triggered, which just makes it quicker and more user friendly.

Let me know what you think:

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

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

void rightAndLeftChoice()
{
 sparki.clearLCD();
 sparki.drawString(10,2, "RIGHT = YES: LEFT = NO");
 sparki.updateLCD();
 delay (5000);
}
void alarmTimeReached()
{
 sparki.clearLCD();
 sparki.drawString(10,2, "Alarm time reached");
 sparki.updateLCD();
 delay (5000);
 sparki.clearLCD();
 sparki.drawString(10,2, "Swipe your hand across my eyes to stop the alarm");
 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.beep();
 delay(500);
 sparki.updateLCD();
delay(5000);
}

void fiveMinuteAlarm()
{
 sparki.clearLCD();
 sparki.drawString(10,2, "5 minute alarm set");
 sparki.beep();
 sparki.updateLCD();
 delay (3000);
 for (int i = 0; i < 3; i=i+1)
 {
 delay (100000);
 sparki.moveLeft(30);
 sparki.moveRight(30);
 }
}
void tenMinuteAlarm()
{
 sparki.clearLCD();
 sparki.drawString(10,2, "10 minute alarm set");
 sparki.beep();
 delay(500);
 sparki.beep();
 sparki.updateLCD();
 delay (5000);
 for (int i = 0; i < 6; i=i+1)
 {
 delay (100000);
 sparki.moveLeft(30);
 sparki.moveRight(30);
 }
}
void fifteenMinuteAlarm()
{
 sparki.clearLCD();
 sparki.drawString(10,2, "15 minute alarm set");
 sparki.beep();
 delay(500);
 sparki.beep();
 sparki.updateLCD();
 delay (5000);
 for (int i = 0; i < 9; i=i+1)
 {
 delay (100000);
 sparki.moveLeft(30);
 sparki.moveRight(30);
 }
}
void twentyMinuteAlarm()
{
 sparki.clearLCD();
 sparki.drawString(10,2, "20 minute alarm set");
 sparki.beep();
 delay(500);
 sparki.beep();
 sparki.updateLCD();
 delay (5000);
 for (int i = 0; i < 12; i=i+1)
 {
 delay (100000);
 sparki.moveLeft(30);
 sparki.moveRight(30);
 }
}
void twentyfiveMinuteAlarm()
{
 sparki.clearLCD();
 sparki.drawString(10,2, "25 minute alarm set");
 sparki.beep();
 delay(500);
 sparki.beep();
 sparki.updateLCD();
 delay (5000);
 for (int i = 0; i < 15; i=i+1)
 {
 delay (100000);
 sparki.moveLeft(30);
 sparki.moveRight(30);
 }
}
void thirtyMinuteAlarm()
{
 sparki.clearLCD();
 sparki.drawString(10,2, "30 minute alarm set");
 sparki.beep();
 delay(500);
 sparki.beep();
 sparki.updateLCD();
 delay (5000);
 for (int i = 0; i < 18; i=i+1)
 {
 delay (100000);
 sparki.moveLeft(30);
 sparki.moveRight(30);
 }
}
void sixtyMinuteAlarm()
{
 sparki.clearLCD();
 sparki.drawString(10,2, "60 minute alarm set");
 sparki.beep();
 delay(500);
 sparki.beep();
 sparki.updateLCD();
 delay (5000);
 for (int i = 0; i < 36; i=i+1)
 {
 delay (100000);
 sparki.moveLeft(30);
 sparki.moveRight(30);

}
}
void fiveMinuteAlarmSet()
{
 fiveMinuteAlarm();
 alarmTimeReached();
 delay(100000);
}
void tenMinuteAlarmSet()
{
 tenMinuteAlarm();
 alarmTimeReached();
 delay(100000);
}
void fifteenMinuteAlarmSet()
{
 fifteenMinuteAlarm();
 alarmTimeReached();
 delay(100000);
}
void twentyMinuteAlarmSet()
{
 twentyMinuteAlarm();
 alarmTimeReached();
 delay(100000);
}
void twentyfiveMinuteAlarmSet()
{
 twentyfiveMinuteAlarm();
 alarmTimeReached();
 delay(100000);
}
void thirtyMinuteAlarmSet()
{
 thirtyMinuteAlarm();
 alarmTimeReached();
 delay(100000);
}
void sixtyMinuteAlarmSet()
{
 sixtyMinuteAlarm();
 alarmTimeReached();
 delay(100000);
}
 
void slowOptions()
{
 sparki.clearLCD();
 sparki.drawString(10,2, "A 5 minute alarm?");
 sparki.beep();
 sparki.updateLCD();
 delay (5000);
rightAndLeftChoice();

 if (sparki.lightRight()<sparki.lightLeft())
 {
 fiveMinuteAlarmSet();
 
 }
else
{
 sparki.clearLCD();
 sparki.drawString(10,2, "A 10 minute alarm?");
 sparki.beep();
 sparki.updateLCD();
 delay (5000);
rightAndLeftChoice();
 if (sparki.lightRight()<sparki.lightLeft())
 {
 tenMinuteAlarmSet();
 }
else
{
 sparki.clearLCD();
 sparki.drawString(10,2, "A 15 minute alarm?");
 sparki.beep();
 sparki.updateLCD();
 delay (5000);
rightAndLeftChoice();
 if (sparki.lightRight()<sparki.lightLeft())
 {
 fifteenMinuteAlarmSet();
 
 }
 else
 {
 sparki.clearLCD();
 sparki.drawString(10,2, "A 20 minute alarm?");
 sparki.beep();
 sparki.updateLCD();
 delay (5000);
rightAndLeftChoice();
 if (sparki.lightRight()<sparki.lightLeft())
 {
 twentyMinuteAlarmSet();
 }
 else
 {
 sparki.clearLCD();
 sparki.drawString(10,2, "A 25 minute alarm?");
 sparki.beep();
 sparki.updateLCD();
 delay (5000);
rightAndLeftChoice();
 if (sparki.lightRight()<sparki.lightLeft())
 {
 twentyfiveMinuteAlarmSet();
 }
 else
 {
 sparki.clearLCD();
 sparki.drawString(10,2, "A 30 minute alarm?");
 sparki.beep();
 sparki.updateLCD();
 delay (5000);
rightAndLeftChoice();
 if (sparki.lightRight()<sparki.lightLeft())
 {
 thirtyMinuteAlarmSet();
 }
 else
 {
 sparki.clearLCD();
 sparki.drawString(10,2, "A 60 minute alarm?");
 sparki.beep();
 sparki.updateLCD();
 delay (5000);
rightAndLeftChoice();
 if (sparki.lightRight()<sparki.lightLeft())
 {
 sixtyMinuteAlarmSet();
 
 }
 }
 }
 }
 }
}
}
 }
void quickOptions()
{
 sparki.clearLCD();
 sparki.drawString(10,1, "The alarm times will appear on screen");
 sparki.beep();
 sparki.updateLCD();
 delay (3000);
 sparki.clearLCD();
 sparki.drawString(10,1, "Select RIGHT for yes and LEFT for no");
 sparki.beep();
 sparki.updateLCD();
 delay (6000);
 sparki.clearLCD();
 for (int i = 0; i < 5; i=i+1)
 {
 sparki.drawString(10,1, "5 minute alarm?");
 sparki.beep();
 sparki.updateLCD();
 delay (5000);
 
 if (sparki.lightRight()<sparki.lightLeft())
 {
 fiveMinuteAlarmSet();
 }
 else
 {
 sparki.clearLCD();
 sparki.drawString(10,1, "10 minute alarm?");
 sparki.beep();
 sparki.updateLCD();
 delay (5000);
 if (sparki.lightRight()<sparki.lightLeft())
 {
 tenMinuteAlarmSet();
 }
 else
 {
 sparki.clearLCD();
 sparki.drawString(10,1, "15 minute alarm?");
 sparki.beep();
 sparki.updateLCD();
 delay (5000);
 if (sparki.lightRight()<sparki.lightLeft())
 {
 fifteenMinuteAlarmSet();
 }
 else
 {
 sparki.clearLCD();
 sparki.drawString(10,1, "20 minute alarm?");
 sparki.beep();
 sparki.updateLCD();
 delay (5000);
 if (sparki.lightRight()<sparki.lightLeft())
 {
 twentyMinuteAlarmSet();
 }
 else
 {
 sparki.clearLCD();
 sparki.drawString(10,1, "25 minute alarm?");
 sparki.beep();
 sparki.updateLCD();
 delay (5000);
 if (sparki.lightRight()<sparki.lightLeft())
 {
 twentyfiveMinuteAlarmSet();
 }
 else
 {
 sparki.clearLCD();
 sparki.drawString(10,1, "30 minute alarm?");
 sparki.beep();
 sparki.updateLCD();
 delay (5000);
 if (sparki.lightRight()<sparki.lightLeft())
 {
 thirtyMinuteAlarmSet();
 }
 else
 {
 sparki.clearLCD();
 sparki.drawString(10,1, "60 minute alarm?");
 sparki.beep();
 sparki.updateLCD();
 delay (5000);
 if (sparki.lightRight()<sparki.lightLeft())
 {
 sixtyMinuteAlarmSet();
 }
 }
 }
 }
 }
 }
 }
 }
 sparki.clearLCD();
 sparki.drawString(10,1, "OK maybe later");
 sparki.beep();
 sparki.updateLCD();
 delay (3000);
}
void loop()
{
 int left = sparki.lightLeft();
 int right = sparki.lightRight();
 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.beep();
 sparki.updateLCD();
 delay (5000);
 sparki.clearLCD();
 sparki.drawString(10,2, "Choose RIGHT sensor for yes");
 sparki.updateLCD();
 delay (5000);
 sparki.clearLCD();
 sparki.drawString(10,2, "Choose LEFT sensor for no");
 sparki.updateLCD();
 delay (5000);
 rightAndLeftChoice();
 if (right<left)
 {
 sparki.clearLCD();
 sparki.drawString(10,2, "Have you set an alarm with me before?");
 sparki.beep();
 sparki.updateLCD();
 delay (5000);
 sparki.clearLCD();
 sparki.drawString(10,2, "RIGHT = Yes : LEFT = No");
 sparki.beep();
 sparki.updateLCD();
 delay (5000);
 if (right>left)
 {
 slowOptions();
 }
 
 else 
 {
 quickOptions();
 }
 }
 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);
}



One thought on “Sparki the Timer Robot-Even more improvements

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