Created
May 28, 2013 03:31
-
-
Save towynlin/5660351 to your computer and use it in GitHub Desktop.
Spark embedded application code (like Arduino/Wiring code) to drive an RC car with the Spark API.
This file contains 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 <stdlib.h> | |
// Motor shield instructions (set control mode jumpers to PWM mode) | |
// http://www.dfrobot.com/wiki/index.php?title=Arduino_Motor_Shield_(L298N)_(SKU:DRI0009) | |
#define LEFT A7 // Motor Shield E1, Arduino D6 | |
#define RIGHT D1 // Motor Shield E2, Arduino D5 | |
void setup() | |
{ | |
pinMode(LEFT, OUTPUT); | |
pinMode(RIGHT, OUTPUT); | |
} | |
void loop() | |
{ | |
} | |
// Callback triggered by the Spark API | |
// See the "Custom Messages" section of | |
// http://docs.sparkdevices.com/ | |
char userFunction(char *message) | |
{ | |
long val = strtol(message + 1, NULL, 10); | |
if ('L' == *message) | |
{ | |
analogWrite(LEFT, val); | |
return 1; | |
} | |
else if ('R' == *message) | |
{ | |
analogWrite(RIGHT, val); | |
return 2; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment