Skip to content

Instantly share code, notes, and snippets.

@jonmarkgo
Created June 18, 2012 17:59
Show Gist options
  • Save jonmarkgo/2949728 to your computer and use it in GitHub Desktop.
Save jonmarkgo/2949728 to your computer and use it in GitHub Desktop.
Respond to commands
void loop()
{
//turn on the LED if the TCP socket is open
if (client.connected()) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
//check for incoming data over TCP
if (client.available()) {
char c = client.read();
//command handler (for dialpad digits)
if (c == '2') {
moveForward();
client.print("forward");
}
else if (c == '4') {
turnLeft();
client.print("left");
}
else if (c == '6') {
turnRight();
client.print("right");
}
else if (c == '8') {
moveBackward();
client.print("back");
}
else if (c == '0') {
stopMovement();
client.print("stopped");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment