Skip to content

Instantly share code, notes, and snippets.

@towynlin
Created May 28, 2013 03:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save towynlin/5660351 to your computer and use it in GitHub Desktop.
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.
#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