Should have had limit switches.

I just started using my little Sparki and I think its pretty cool.

It’s a whole lot of gadgets in a small package.

I wish the program memory was a bit bigger cause just tweeking the default code I’m at 20k of 28k. I don’t know if I can make the little guy handle every single feature at the same time and fit it in the memory.

[code]#include <Sparki.h> // include the robot library
int neck;
int color_r;
int color_g;
int color_b;

// Default program for Sparki but starts in
// remote mode instead of autonomous
// Remote Control Values
// /------^-----------------------------
// | |
// | 69(turn L) 70(UP) 71(turn R) |
// | 68(LEFT) 64(STOP) 67(RIGHT) |
// | 7(Close G) 21(DOWN) 9(Open G) |
// | 22(MINUS) 25(ZERO) 13(PLUS) |
// | 12(ONE) 24(TWO) 94(THREE) |
// | 8(FOUR) 28(FIVE) 90(SIX) |
// | 66(SEVEN) 82(EIGHT) 74(NINE) |
// _________________________/
// /------^-----
// | |
// | 69 70 71 |
// | 68 64 67 |
// | 7 21 9 |
// | 22 25 13 |
// | 12 24 94 |
// | 8 28 90 |
// | 66 82 74 |
// _
/

void setup() {
neck=0;
color_r=0;
color_g=0;
color_b=0;

sparki.servo(neck); // center the servo
}

int program = false;
void loop() {

 sparki.clearLCD();

int cm = sparki.ping(); // measures the distance with Sparki's eyes

sparki.print("Distance: "); 
sparki.print(cm); // tells the distance to the computer
sparki.println(" cm"); 

if(cm != -1) // make sure its not too close or too far
{ 
    if(cm < 10) // if the distance measured is less than 10 centimeters
    {
        sparki.beep(); // beep!
    }
}

sparki.updateLCD();
delay(100); // wait 0.1 seconds (100 milliseconds)

//Scan for IR Receiver
int code = sparki.readIR();

// if there is a valid remote button press
if(code != -1){
// sparki.moveStop(); // stop the motor
// sparki.RGB(RGB_OFF); // clear the RGB
program = false; // turn off the starter program
}
switch(code){
case 70: sparki.beep(); // beep!
sparki.moveForward(5); break;
case 21: sparki.beep(); // beep!
sparki.moveBackward(5); break;

case 67: sparki.beep(); // beep!
sparki.moveRight(15); break;
case 71: sparki.beep(); // beep!
sparki.moveRight(15); break;
case 68: sparki.beep(); // beep!
sparki.moveLeft(15); break;
case 69: sparki.beep(); // beep!
sparki.moveLeft(15); break;
case 64: sparki.beep(); // beep!
sparki.moveStop();
sparki.gripperStop(); break;

// Gripper Buttons
case 9:    sparki.beep(); // beep! 
         sparki.gripperOpen();
         delay(500);
         sparki.gripperStop(); break;      
case 7:    sparki.beep(); // beep! 
         sparki.gripperClose();
         delay(500);
         sparki.gripperStop(); break;      

// RGB
case 25:   sparki.beep(); // beep! 
         sparki.RGB(RGB_OFF); break;
case 12:   sparki.beep(); // beep! 
         color_r=color_r+10;
          sparki.RGB(color_r,color_g,color_b); break;
case 24:   sparki.beep(); // beep! 
         color_g=color_g+10;
          sparki.RGB(color_r,color_g,color_b); break;
case 94:   sparki.beep(); // beep! 
         color_b=color_b+10;
          sparki.RGB(color_r,color_g,color_b); break;

// Servo
case 90:   sparki.beep(); // beep! 
         neck = neck + 5;
         sparki.servo(neck); break;
case 28:   sparki.beep(); // beep! 
         neck = 0;
         sparki.servo(neck); break;
case 8:    sparki.beep(); // beep! 
         neck = neck - 5;
         sparki.servo(neck); break;

// buzzer
case 74: sparki.beep(); break;

// Program Control
case 66:  
  sparki.moveStop();
  color_r=0;
  color_g=0;
  color_b=0;
  sparki.RGB(0,0,0);
  program = false; break;
case 82:  
  program = true; break;

}

// Run Autonomy Code if
if(program == true){
sparki.moveForward();
sparki.RGB(RGB_GREEN);
int cm = sparki.ping(); // measures the distance with Sparki’s eyes

if(cm != -1) // make sure its not too close or too far
{ 
    if(cm < 20) // if the distance measured is less than 20 centimeters
    {
        sparki.RGB(RGB_RED); // turn the led red
        sparki.beep(); // beep!
        sparki.moveBackward(10); // move sparki backwards
        sparki.moveRight(30);
    }
}
    
delay(100); // wait 0.1 seconds (100 milliseconds)

}
}[/code]

I tweeked the code so that the remote command confirms by a beep, the lcd show’s the distance (I thought that was really cool), the little guy moves little steps instead of going buck wild until a new command is sent. Oh and default is remote controlled instead of autonomous. The “neck” and grabber moves in steps too. So does the LCD colors, they combine and add in intensity.

Bugs I’ve noticed so far:

Sometimes the code does not upload, and I try a second or third time and it does. I don’t know if why this was the case.

I really don’t like from the original code that the motors (neck and grabber) just keep going once it reaches the end. I wish either there was limit switches to stop the motor or some kind of timing in the code to stop it. Thats why I changed it to small steps.

If you add blue and green light and then add red, the other two colors start to drop and when you get to full intensity, it basically turns off the other two colors. But no where in the code does it say to do that. So I’m thinking its something in the library, but I can’t see yet where that is to debug.

I know this has been stated already, but the bluetooth module won’t connect with LCD in the way. I have to pull out the LCD and connect the bluetooth.

I have carpet where I live and it gets stuck once and a while in it.

But a really cool little toy. I can see it being helpful to teach robotics, but more about mating software and hardware. ( I feel a big part of robotics is buidling the hardware, however that part is done.) I see this more as a software intensive project toy. (if it was like you can add and remove hardware, I can see it be more of a mix of hw/sw.)

Just had a small suggestion…
Always beep unless you don’t have a valid command, so you can move all the sparki.beeps out of the case statements…

  boolean doBeep = true;

  switch(code){
    case 70:   sparki.moveForward(5); break;
    case 21:   sparki.moveBackward(5); break;
    <all your case statements>
    default:  doBeep = false;
    }
    if(doBeep) sparki.beep(); 

[quote=“jle”]Just had a small suggestion…
Always beep unless you don’t have a valid command, so you can move all the sparki.beeps out of the case statements…

[code]
boolean doBeep = true;

switch(code){
case 70: sparki.moveForward(5); break;
case 21: sparki.moveBackward(5); break;

default: doBeep = false;
}
if(doBeep) sparki.beep();
[/code][/quote]

Very nice, minimizes the code.

Thanks!