LED Blinking Via Terminal

I’ve just managed to control 2 LEDs over the internet by following the tutorial. I am using D0 and D1 on the board, but when I typed this into terminal I got a -1 response:

curl https://api.spark.io/v1/devices/55ff70065075555355411787/led
-d access_token=xxxxxx
-d params=D0,HIGH

As soon as I changed the last statment to D1,HIGH, then D2,HIGH, both my LEDs came on and I got a 1 as a response on both occasions.

Is this something to do with this line of code:

int pinNumber = (command.charAt(1) - ‘0’) - 1;

I take it charAt(1) is looking at the character ‘1’ from “D1,HIGH”? If so why do I have to increment the number (i.e., D0 to 1, and D1 to 2)?

Which example would that be? I will take a look at the firmware :wink:

Thanks :smile:

Its in the “annotated examples”.

I think I have figured it out…

You don’t need to have (-1) outside the brackets:

command.charAt(1) - ‘0’;

And not

(command.charAt(1) - ‘0’) -1;

I fired up my Arduino Uno and had a play with that line of code. It turns out that subtracting the char ‘0’ is the same as subtracting the decimal 48.

Now if I parse the string “D0”, I get 0 and not -1.

1 Like