Skip to content

Instantly share code, notes, and snippets.

@bnferguson
Last active December 30, 2015 15:09
Show Gist options
  • Save bnferguson/7846950 to your computer and use it in GitHub Desktop.
Save bnferguson/7846950 to your computer and use it in GitHub Desktop.
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