Created
June 18, 2012 17:59
-
-
Save jonmarkgo/2949728 to your computer and use it in GitHub Desktop.
Respond to commands
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
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