Sparki the Timer Robot

So after working on Sparki the snooze alarm I decided to experiment with Sparki the Timer Robot.

In the following code I gave the user the option of setting a five minute alarm or a ten minute alarm using Sparki’s light sensors as buttons. I find that five minute and ten minute alarms are most commonly used for cooking, timers, and children (lol) so thought that would be the most helpful.

I enjoyed writing this but I think I will edit the code so that the alarm sounds for longer but the user has the option to “switch” it off earlier.

13221667_10208793227204600_8850987448344265824_n

Here is 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);
 for (int i = 0; i < 10; i=i+1)
 {
 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);
 }
}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);
 for (int i = 0; i < 10; i=i+1)
 {
 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);
 }
 }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

Sparki the snooze alarm-improvement

So my last post I shared the code to turn Sparki into a “snooze alarm” – the alarm you set for ten minutes after your actual alarm goes off while you doze back to sleep.

In this post I’m going to share the improvements I made after re-looking at the code, using the light sensors as a button to switch off the alarm if you are awake, or else it continues so that you do wake up.

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

void setup() {
 sparki.RGB(RGB_OFF);
 sparki.servo(60);
}
void loop()
{
 
 for (int i = 0; i < 6; i=i+1)
 {
 delay (100000);
 sparki.moveLeft(30);
 sparki.moveRight(30);
 }
 sparki.clearLCD();
 sparki.drawString(10,2, "Good morning Ash");
 sparki.updateLCD();
 delay (3000);
 for (int i = 0; i < 10; i=i+1)
 {
 int left = sparki.lightLeft();
 int right = sparki.lightRight();
 if (left>=right)
 {
 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, "Hope you have a good day");
 sparki.updateLCD();
 delay (3000);
 sparki.clearLCD();
 sparki.drawString(10,2, "ha en fin dag");
 sparki.updateLCD();
 delay (3000);
}

Let me know what you think ūüôā

I cant believe how versatile Sparki is- can be used for soooo many things ūüôā ūüôā

13151622_10208751226194601_4580888961498116869_n

 

Sparki the snooze alarm

Hey everyone

So you know that time in the morning when you switch off your alarm or hit snooze and lie in bed staring at the ceiling, staring at your smartphone or dozing back to sleep? Well Sparki can now be my snooze alarm.

For those ten minutes Sparki will move slightly disturbing me from falling back to sleep, and once those ten minutes are up, Sparki will play an annoying tune, guaranteed to get me out of bed!

He’ll also wish me a nice day!

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

void setup() {
 sparki.RGB(RGB_OFF);
 sparki.servo(60);
}
void loop()
{
 
 for (int i = 0; i < 6; i=i+1)
 {
 delay (100000);
 sparki.moveLeft(30);
 sparki.moveRight(30);
 }
 sparki.clearLCD();
 sparki.drawString(10,2, "Good morning Ash");
 sparki.updateLCD();
 delay (3000);
 int left = sparki.lightLeft();
 int right = sparki.lightRight();
 if (left>=right)
 {
 for (int i = 0; i < 6; i=i+1)
 {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, "Hope you have a good day");
 sparki.updateLCD();
 delay (3000);
 sparki.clearLCD();
 sparki.drawString(10,2, "ha en fin dag");
 sparki.updateLCD();
 delay (3000);
}

Let me know what you think….there are loads of ideas I have for this code ūüôā

13138730_10208751226474608_3515831574067619993_n

 

Sparki’s new board

Hey everyone

So you may remember Sparki has been a little worse for wear recently, with no eyes (ultrasonic range finder).

Well now that has changed! The lovely people over at Arcbotics have sent me a replacement board for free and one of the lovely tutors at my place of work has FIXED Sparki for me! I am so happy!

So here is a picture of Sparki looking shiny and happy with his new board and eyes that work:

Sparki goes to college

Hi everyone

So I work in a FE college in BTEC level 2 ICT as a learning assistant and I recently took my Sparki in to give them a taster of programming robotics.

We worked on a simple light following program which the students wrote, debugged and tested themselves also giving ideas about how to improve the program in the future and it worked really well.

Anyway they then had some free time with Sparki and here is an example of one of the codes they had written to turn Sparki into some kind of disco ball:

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

void setup() {
 sparki.servo(0);
 }
 void loop() {
 sparki.RGB(0,255,0);
 int time=3;
 // make red brighter
 for(int i=0; i<100; i++){
 sparki.RGB(i,0,0);
 delay(time);
 }
 // make red dimmer
 for(int i=100; i>0; i--){
 sparki.RGB(i,0,0);
 delay(time);
 }

// make green brighter
 for(int i=0; i<100; i++){
 sparki.RGB(0,i,0);
 delay(time);
 }
 // make green dimmer
 for(int i=100; i>0; i--){
 sparki.RGB(0,i,0);
 delay(time);
 }

// make blue brighter
 for(int i=0; i<100; i++){
 sparki.RGB(0,0,i);
 delay(time);
 }
 // make blue dimmer
 for(int i=100; i>0; i--){
 sparki.RGB(0,0,i);
 delay(time);
 }}

 

13139307_10208751225754590_8957404330261514653_n

 

Conversation and entertainment bot

Hi everybody

So this code puts together a lot of things I have been writing about including the ir sensor as a way for Sparki to “see” and the touch sensor….unfortunately my sound sensor has broken (electrocuting me in the process!)

sparki2

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

void setup()
{
 sparki.servo(0);
   sparki.clearLCD();
  sparki.drawString(10, 1, "Hello human ");
  sparki.updateLCD();
  delay(1000);
    sparki.clearLCD();
  sparki.drawString(10, 1, "time for a bot hug");
  sparki.updateLCD();
  delay(1000);
int shake=analogRead(8);
 sparki.print(shake);
      sparki.updateLCD();
      delay(1000);
       if(shake>100)
      {
      sparki.beep();
      sparki.gripperClose(6);
      delay(1000);
      sparki.gripperOpen(6);
      delay(1000);
    sparki.clearLCD();
sparki.drawString(10,2, "yey friends!");
sparki.updateLCD();
delay(3000);}
}
   
    void loop()
{
  sparki.servo(0);
  sparki.clearLCD();
  sparki.drawString(10, 1, "I am in entertainment BOT mode");
  sparki.updateLCD();
  delay(1000);
	sparki.moveLeft(30);
	sparki.moveRight(30);
	delay(1000);
	sparki.beep(640, 200);
	delay(200);
	sparki.beep(440, 200);
	delay(100);
		int lightLeft = sparki.lightLeft();
		int lightCenter = sparki.lightCenter();
		int lightRight = sparki.lightRight();
		int edgeLeft = sparki.edgeLeft();
		int edgeRight = sparki.edgeRight();
		sparki.servo(0);
		sparki.RGB(0,220,0);
		if(((lightCenter>lightLeft)&&(lightRight>lightLeft)))
		{

			sparki.RGB(RGB_RED);
              delay(500);
            
              sparki.RGB(RGB_ORANGE);
              delay(500);
              
              sparki.RGB(RGB_YELLOW);
              delay(500);
              
              sparki.RGB(RGB_GREEN);
              delay(500);
              sparki.beep();
              
              sparki.RGB(RGB_BLUE);
              delay(500);
              
              sparki.RGB(RGB_INDIGO);
              delay(500);
            
              sparki.RGB(RGB_VIOLET);
              delay(500);
              sparki.beep();
            
              sparki.RGB(RGB_WHITE);
              delay(500);
              
              sparki.RGB(RGB_OFF);
              delay(500);
		}
		else
		{
			delay(1000);
		}
		if(((lightLeft>lightRight)&&(lightCenter>lightRight)))
		{
			
			sparki.beep(840, 400);
			delay(200);
			sparki.beep(640, 400);
			delay(200);
			sparki.beep(440, 400);
			delay(200);
			sparki.beep(340, 400);
			delay(200);
			sparki.beep(640, 800);
			delay(200);
			sparki.beep(440, 800);
			delay(200);
			sparki.beep(340, 400);
			delay(200);
			sparki.beep(440, 400);
			delay(200);
			sparki.beep(640, 400);
			delay(200);
		}
		else
		{
			delay(1000);
		}
randomSeed(analogRead(1));
  int response = random(0, 12);
  sparki.clearLCD();
  sparki.print(response);
  sparki.updateLCD();
  delay(2000);
  if((response>=0) && (response <3))
  {
    sparki.clearLCD();
    sparki.drawString(10, 1, "When I grow up I want to be a social domestic bot");
    sparki.updateLCD();
    delay(3000);
    sparki.moveRight(90);
    sparki.moveForward(5);
    sparki.moveLeft(90);
    sparki.beep();
    sparki.moveBackward(5);
    sparki.moveRight(90);
    sparki.moveForward(5);
    sparki.beep();
    sparki.moveLeft(90);
    sparki.moveBackward(5);
    sparki.moveRight(90);
    sparki.beep();
    sparki.moveForward(5);
    sparki.moveLeft(90);
    sparki.moveBackward(5);
  }
 else if((response>=3) && (response <=8))
  {
        sparki.clearLCD();
sparki.drawString(10,2, "Preparing lazers for combat");
sparki.updateLCD();
delay(3000);
sparki.beep(740, 200);
sparki.clearLCD();
sparki.drawString(10,2, "Pew Pew");
sparki.updateLCD();
delay(1000);
sparki.beep(740,200);
delay(100);
sparki.beep(440,200);
sparki.moveRight(10);
sparki.moveLeft(10);
delay(2000);
      }
      
    else 
      {
        sparki.clearLCD();
sparki.drawString(10,2, "I will be kind to you when we robots take over the world");
sparki.updateLCD();
delay(3000);
 sparki.moveLeft(90);
  sparki.moveForward(5);
  sparki.beep();
  sparki.moveBackward(5);
  sparki.moveForward(5);
  sparki.RGB(RGB_BLUE);
  sparki.moveBackward(5);
  sparki.beep();
  sparki.moveForward(5);
  sparki.moveRight(180);
  sparki.RGB(RGB_GREEN);
  sparki.moveLeft(7);
  sparki.beep();
  sparki.moveRight(14);
  sparki.moveLeft(7);
  sparki.RGB(RGB_RED);

      }
      
		if(edgeLeft>1)
		{
			sparki.RGB(220,0,0);
			sparki.beep(840, 400);
			sparki.moveLeft(90);
			sparki.beep(440, 200);
			sparki.moveRight(90);
			sparki.beep(340, 200);
			delay(100);
			sparki.beep(540, 200);
			sparki.RGB(0,0,220);
			sparki.beep(440, 400);
			sparki.moveForward(5);
			delay(200);
			sparki.beep(640, 400);
			delay(200);
			sparki.beep(740, 500);
			sparki.moveBackward(5);
			delay(200);
		}
	
		if(edgeLeft>600)
		{
			
                      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);
		}

  randomSeed(analogRead(1));
  int response1 = random(0, 10);
  sparki.clearLCD();
  sparki.print(response1);
  sparki.updateLCD();
  delay(1000);
  if((response1>=0) && (response1 <3))
  {
    sparki.clearLCD();
    sparki.drawString(10, 1, "Today I organised my data stream");
    sparki.updateLCD();
    delay(3000);
       sparki.beep(440, 600);
			delay(400);
			sparki.beep(540, 400);
			delay(400);
			sparki.beep(640, 200);
			delay(200);
			sparki.beep(740, 200);
			delay(200);
			sparki.beep(640, 400);
			delay(400);
			sparki.beep(540, 200);
			delay(400);
			sparki.beep(440, 200);
sparki.clearLCD();
sparki.drawString(10,1, "Perfect");
    sparki.updateLCD();
    delay(3000);
  }
 else if((response1>=3) && (response1 <=8))
  {
sparki.clearLCD();
sparki.drawString(10,2, "Shake my hand human");
sparki.updateLCD();
delay(3000);
int shake=analogRead(8);
 sparki.print(shake);
      sparki.updateLCD();
      delay(1000);
       if(shake>100)
      {
      sparki.beep();
      sparki.gripperClose(6);
      delay(1000);
      sparki.gripperOpen(6);
      delay(1000);
    sparki.clearLCD();
sparki.drawString(10,2, "yey friends!");
sparki.updateLCD();
delay(3000);
      }
  }
  
    else 
      {
        sparki.clearLCD();
sparki.drawString(10,2, "Today I beamed Jim. He's my cousin in California!");
sparki.updateLCD();
delay(3000);
 sparki.moveRight(90);
  sparki.moveForward(5);
  sparki.RGB(RGB_BLUE);
  sparki.beep();
  sparki.moveBackward(5);
  sparki.moveRight(50);
  sparki.moveBackward(5);
  sparki.moveLeft(50);
  sparki.RGB(RGB_GREEN);
  sparki.beep();
    }
    if(edgeRight>1)
		{
			sparki.RGB(220,0,0);
			sparki.beep(740, 200);
			sparki.moveRight(90);
			sparki.beep(840, 400);
			sparki.moveLeft(90);
			sparki.beep(440, 400);
			delay(100);
			sparki.beep(740, 200);
			sparki.RGB(0,0,220);
			sparki.beep(640, 200);
			sparki.moveBackward(5);
			delay(200);
			sparki.beep(440, 400);
			delay(200);
			sparki.beep(740, 500);
			sparki.moveForward(5);
			delay(200);
		}
	
		if(edgeRight>600)
		{
			
                        sparki.beep(440, 600);
			delay(400);
			sparki.beep(640, 400);
			delay(400);
			sparki.beep(740, 200);
			delay(200);
			sparki.beep(440, 200);
			delay(200);
			sparki.beep(640, 400);
			delay(400);
			sparki.beep(540, 200);
			delay(400);
			sparki.beep(740, 200);
}
    sparki.clearLCD();
sparki.drawString(10,2, "lets play a game");
sparki.updateLCD();
delay(3000);
randomSeed(analogRead(1));
  int response2 = random(1, 3);
  if (response2==1)
  {
  sparki.clearLCD();
  sparki.drawString(20,2,"Lets play robot snap");
  sparki.updateLCD();
  delay(2000);
  for (int i = 0; i < 5; i=i+1)
  {
  randomSeed(analogRead(1));
  int responsea = random(1, 3);
  if (responsea==1)
  {
    sparki.clearLCD(); // wipe the LCD clear
    sparki.drawRect(5,5,30,10); //small empty rectangle in upper-left
    sparki.updateLCD(); // put the drawings on the screen
    delay(500);
    sparki.clearLCD();
  }
  if (responsea==2)
  {
    sparki.clearLCD(); // wipe the LCD clear
    sparki.drawCircle(10,10,5); //small empty circle in upper-left
    sparki.updateLCD(); // put the drawings on the screen
    delay(500);
    sparki.clearLCD();
    
   
  }
  if (responsea==3)
  {
    sparki.clearLCD(); // wipe the LCD clear
    sparki.drawCircleFilled(90,40,20); // big filled circle in lower-right
    sparki.updateLCD(); // put the drawings on the screen
    delay(500);
    sparki.clearLCD();
    
  }
  randomSeed(analogRead(1));
  int responseb = random(1, 3);
  if (responseb==1)
  {
    sparki.clearLCD(); // wipe the LCD clear
    sparki.drawRect(5,5,30,10); //small empty rectangle in upper-left
    sparki.updateLCD(); // put the drawings on the screen
    delay(500);
     sparki.clearLCD();
    
  }
  if (responseb==2)
  {
    sparki.clearLCD(); // wipe the LCD clear
    sparki.drawCircleFilled(90,40,20); //small empty circle in upper-left
    sparki.updateLCD(); // put the drawings on the screen
    delay(500);
     sparki.clearLCD();
  
  }
  if (responseb==3)
  {
    sparki.clearLCD(); // wipe the LCD clear
    sparki.drawCircle(10,10,5); 
    sparki.updateLCD(); // put the drawings on the screen
    delay(500);
     sparki.clearLCD();
  }
  if ((responsea==1) && (responseb==1))
  {
    delay(1000);
    int shake=analogRead(8);
       if(shake>100)
      {
        sparki.clearLCD();
        sparki.drawString(20,2,"Well done! You were first");
        sparki.updateLCD();
        delay(1000);
      }
      else
      {
        sparki.clearLCD();
        sparki.drawString(20,2,"Snap! I win!");
        sparki.updateLCD();
        delay(1000);
      }
  }
   if ((responsea==2) && (responseb==2))
  {
    delay(1000);
    int shake=analogRead(8);
       if(shake>100)
      {
        sparki.clearLCD();
        sparki.drawString(20,2,"Well done! You were first");
        sparki.updateLCD();
        delay(1000);
      }
      else
      {
        sparki.clearLCD();
        sparki.drawString(20,2,"Snap! I win!");
        sparki.updateLCD();
        delay(1000);
      }
  }
   if ((responsea==3) && (responseb==3))
  {
    delay(1000);
    int shake=analogRead(8);
       if(shake>100)
      {
        sparki.clearLCD();
        sparki.drawString(20,2,"Well done! You were first");
        sparki.updateLCD();
        delay(1000);
      }
      else
      {
        sparki.clearLCD();
        sparki.drawString(20,2,"Snap! I win!");
        sparki.updateLCD();
        delay(1000);
      }
  }
  }
  }
  if ((response2==2)|| (response2==3))
  {
    sparki.clearLCD();
      sparki.drawString(20,2, "Let's play robot or human!");
      sparki.updateLCD();
      delay(2000);
        sparki.clearLCD();
      sparki.drawString(10,1, "The rules are easy!");// Robot tries to catches human, and human tries to escape robot! I will be...");
      sparki.updateLCD();
      delay(2000);
      sparki.clearLCD();
       sparki.drawString(10,1, "Robot tries to catch the human...");// and human tries to escape robot! I will be...");
      sparki.updateLCD();
      delay(2000);
      sparki.clearLCD();
       sparki.drawString(10,1, "... and the human tries to escape the robot!");
      sparki.updateLCD();
      delay(2000);
      sparki.clearLCD();
      sparki.beep();
      randomSeed(analogRead(1));
  int responserh = random(1, 10);
if (responserh<=5)
{
   sparki.clearLCD();
      sparki.drawString(20,2, "I will be the robot");
      sparki.updateLCD();
      delay(2000);
      sparki.beep();
      for (int i = 0; i < 5; i=i+1)
      {
        pinMode (3, INPUT); //Sensor output
  sparki.clearLCD();
sparki.print ("Sensor: ");
 sparki.println (digitalRead(3)); //print the sensor output
 sparki.updateLCD();
 delay (1500); 
 if (digitalRead(3) >0 )
 {
   sparki.moveRight(10);
   sparki.clearLCD();
      sparki.drawString(20,2, "Where is that silly human??");
      sparki.updateLCD();
      delay(1000);
 }
 if (digitalRead(3) <1 )
 {
   sparki.moveForward();
   sparki.clearLCD();
      sparki.drawString(20,2, "robot will catch you!");
      sparki.updateLCD();
      delay (1000);
 }
       sparki.clearLCD();
      sparki.drawString(20,2, "I'm a good robot!");
      sparki.updateLCD();
      delay(2000);
}
}
if (responserh>5)
{
   sparki.clearLCD();
      sparki.drawString(20,2, "I will be the human");
      sparki.updateLCD();
      delay(2000);
      sparki.beep();
      for (int i = 0; i < 5; i=i+1)
      {
      pinMode (3, INPUT); //Sensor output
  sparki.clearLCD();
sparki.print ("Sensor: ");
 sparki.println (digitalRead(3)); //print the sensor output
 sparki.updateLCD();
 delay (1500); 
 while (digitalRead(3) >0 )
 {
   sparki.moveForward();
   sparki.clearLCD();
      sparki.drawString(20,2, "Yey! escape!");
      sparki.updateLCD();
      delay(1000);
 }
 while (digitalRead(3) <1 )
 {
   sparki.moveRight(10);
        sparki.clearLCD();
      sparki.drawString(20,2, "Uh, oh");
      sparki.updateLCD();
      delay(1000);
      }
       sparki.clearLCD();
      sparki.drawString(20,2, "Human is free! Woo!");
      sparki.updateLCD();
      delay(2000);
}
}
      }

    
}