Skip to content

Instantly share code, notes, and snippets.

@mithi
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mithi/edd8be39118d3fa80552 to your computer and use it in GitHub Desktop.
Save mithi/edd8be39118d3fa80552 to your computer and use it in GitHub Desktop.
line following program for arcbotics sparki
#include <Sparki.h>
class LineSense{
int threshold;
public:
LineSense(int thresh){
threshold = thresh;
}
boolean isLine(int sensorValue){
return sensorValue < threshold;
}
void follow(){
if (isLine(sparki.lineLeft())){
sparki.moveLeft();
}else {
isLine(sparki.lineRight()) ? sparki.moveRight() : sparki.moveForward();
}
}
void show(){
sparki.clearLCD();
sparki.print("left: ");
sparki.println(sparki.lineLeft());
sparki.print("center: ");
sparki.println(sparki.lineCenter());
sparki.print("right: ");
sparki.println(sparki.lineRight());
sparki.updateLCD();
}
void act(){
show();
follow();
delay(75);
}
};
LineSense lineSense(500);
void setup(){
}
void loop(){
lineSense.act();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment