Skip to content

Instantly share code, notes, and snippets.

@mithi
Last active Aug 29, 2015
Embed
What would you like to do?
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