Last active
December 30, 2015 15:09
-
-
Save bnferguson/7846950 to your computer and use it in GitHub Desktop.
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
Servo leftWheel; | |
Servo rightWheel; | |
int drive(String command); | |
int stop(String command); | |
void setup() { | |
leftWheel.attach(A0); | |
rightWheel.attach(A1); | |
Spark.function("drive", drive); | |
Spark.function("stop", stop); | |
} | |
int stop(String command) { | |
leftWheel.detach(); | |
rightWheel.detach(); | |
leftWheel.attach(A0); | |
rightWheel.attach(A1); | |
return 1; | |
} | |
int drive(String command) { | |
if (command == "forward") { | |
leftWheel.write(180); | |
rightWheel.write(0); | |
return 1; | |
} | |
if (command == "back") { | |
leftWheel.write(0); | |
rightWheel.write(180); | |
return 1; | |
} | |
if (command == "left") { | |
leftWheel.write(45); | |
rightWheel.write(45); | |
return 1; | |
} | |
if (command == "right") { | |
leftWheel.write(135); | |
rightWheel.write(135); | |
return 1; | |
} | |
return -1; | |
} | |
void loop() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment