Spark Cloud POST not working?
Closed this issue · 3 comments
Hello,
I have flashed the following code onto my Spark Core and tried to POST via the command prompt to control an LED, but for some reason it is not working as intended..
int blue = D7;
int led1 = D6;
int led2 = D5;
int led3 = D4;
int led4 = D3;
int led5 = D2;
int led6 = D1;
int button = D0;
void setup()
{
Spark.function("bigblue", bigblue);
pinMode(blue, OUTPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(button, INPUT);
}
void loop()
{
digitalWrite(blue, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
attachInterrupt(button, check, CHANGE);
delay(300);
attachInterrupt(button, check, CHANGE);
digitalWrite(blue, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
attachInterrupt(button, check, CHANGE);
delay(300);
attachInterrupt(button, check, CHANGE);
digitalWrite(blue, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, HIGH);
attachInterrupt(button, check, CHANGE);
delay(300);
attachInterrupt(button, check, CHANGE);
digitalWrite(blue, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
attachInterrupt(button, check, CHANGE);
delay(300);
attachInterrupt(button, check, CHANGE);
digitalWrite(blue, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led4, HIGH);
attachInterrupt(button, check, CHANGE);
delay(300);
attachInterrupt(button, check, CHANGE);
digitalWrite(blue, LOW);
digitalWrite(led4, LOW);
digitalWrite(led3, HIGH);
attachInterrupt(button, check, CHANGE);
delay(300);
attachInterrupt(button, check, CHANGE);
}
void check()
{
if (digitalRead(button) == HIGH)
{
digitalWrite(led1, HIGH);
}
else if (digitalRead(button) == LOW)
{
digitalWrite(led1, LOW);
}
}
int bigblue(String onoff)
{
if (onoff.substring (0,1) == "ON")
{
digitalWrite(led6, HIGH);
}
else if (onoff.substring (0,2) == "OFF")
{
digitalWrite(led6, LOW);
}
else
{
return -1;
}
return 1;
}
It should go over to digitalWrite(led6, HIGH) and turn the LED on, but instead just goes straight to the "else" option and returns -1. If I return 1 under else, it returns 1.
Thanks in advance!
@Voltezk, this is not a Spark-cli related question. Do you mind shifting it over to http://community.spark.io for us to better advice you on the issue?
Sorry, I wasn't sure where to post this.
and sure, please move to wherever appropriate :)
@kennethlimcp thanks for the help!
@Voltezk glad to see you got it figured out!
Closing this issue.