Last active
July 30, 2016 05:59
-
-
Save jessecogollo/e92ea76cb8d3993eb20065c7c262a35e 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
// This #include statement was automatically added by the Particle IDE. | |
#include "InternetButton/InternetButton.h" | |
// #include <iostream> | |
// #include <string> | |
int tinkerDigitalWrite(String command); | |
InternetButton b = InternetButton(); | |
/* This function is called once at start up ----------------------------------*/ | |
void setup() | |
{ | |
//Setup the Tinker application here | |
Spark.function("digitalwrite", tinkerDigitalWrite); | |
b.begin(); | |
} | |
/* This function loops forever --------------------------------------------*/ | |
void loop() | |
{ | |
//This will run in a loop | |
} | |
int tinkerDigitalWrite(String command) | |
{ | |
int pinNumber = command.charAt(1) - '0'; | |
if(command.startsWith("D")) | |
{ | |
String red = command.substring(9,11); | |
String green = command.substring(12,15); | |
String blue = command.substring(16,19); | |
// b.ledOn(pinNumber,red , 'green', 'blue'); | |
int ResultRed; // number which will contain the result | |
int Succeeded = sscanf ( red, "%d", &ResultRed ); | |
if ( !Succeeded || Succeeded == EOF ) // check if something went wrong during the conversion | |
ResultRed = 0; | |
int ResultGreen; // number which will contain the result | |
int SucceededGreen = sscanf ( green, "%d", &ResultGreen ); | |
if ( !SucceededGreen || SucceededGreen == EOF ) // check if something went wrong during the conversion | |
ResultGreen = 0; | |
int ResultBlue; // number which will contain the result | |
int SucceededBlue = sscanf ( blue, "%d", &ResultBlue ); | |
if ( !SucceededBlue || SucceededBlue == EOF ) // check if something went wrong during the conversion | |
ResultBlue = 0; | |
b.ledOn(pinNumber ,ResultRed , ResultGreen, ResultBlue); | |
return 1; | |
} | |
else if(command.startsWith("A")) | |
{ | |
b.ledOff(pinNumber); | |
return 1; | |
} | |
else return -3; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment