Last active
August 29, 2015 14:23
-
-
Save mithi/edd8be39118d3fa80552 to your computer and use it in GitHub Desktop.
line following program for arcbotics sparki
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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