Updated line following

This updated version of the code worked for me with the line following sheet printed on 8.5" x 11" paper:

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

void setup()
{
}

void loop() {
int threshold = 700;

int lineLeft = sparki.lineLeft(); // measure the left IR sensor
int lineCenter = sparki.lineCenter(); // measure the center IR sensor
int lineRight = sparki.lineRight(); // measure the right IR sensor

if ( lineLeft < threshold ) // if line is below left line sensor
{
sparki.moveLeft(); // turn left
}

if ( lineRight < threshold ) // if line is below right line sensor
{
sparki.moveRight(); // turn right
}

// if the center line sensor is the only one reading a line
if ( (lineCenter < threshold) && (lineLeft > threshold) && (lineRight > threshold) )
{
sparki.moveForward(); // move forward
}

sparki.clearLCD(); // wipe the screen
sparki.println();

sparki.print("Line Left: ");
sparki.println(lineLeft);

sparki.print("Line Center: ");
sparki.println(lineCenter);

sparki.print("Line Right: ");
sparki.println(lineRight);

sparki.println();
sparki.updateLCD(); // display all of the information written to the screen

delay(100); // wait 0.1 seconds
}

Thanks, I really like the addition of the screen display. I’ll include this in the next update!

What line following sheet? Is there a link somewhere or did you make one up? Thanks.

Here is an unofficial link: http://www.flickr.com/photos/arcbotics/11948073966/ and: http://www.flickr.com/photos/arcbotics/11947680414/. It appears they are designed to be printed on A2 paper (594 x 420 mm / 23.4 x 16.5 in), but I was able to splice two 8.5 x 11" sheets using photo editing software.

Line following without the need for a threshold.

[code]
#include <Sparki.h> // include the sparki library

void setup()
{
}

void loop() {
int lineLeft = sparki.lineLeft(); // measure the left IR sensor
int lineCenter = sparki.lineCenter(); // measure the center IR sensor
int lineRight = sparki.lineRight(); // measure the right IR sensor

// is the center sensor picking up a line?
if ( (lineCenter < lineLeft) && (lineCenter < lineRight) )
{
sparki.moveForward(); // move forward
}
else if ( lineRight > lineCenter ) // is the right sensor on white?
{
sparki.moveLeft(); // turn left
}
else if ( lineLeft > lineCenter ) // is the left sensor on white?
{
sparki.moveRight(); // turn right
}

delay(100); // wait 0.1 seconds
}[/code]