Hi
I have made this code, but it dont act as I suppossed... I won to send a string from my BT, to set a pin (ex. pin13) so I would like to send a string like:
L, 13, 1
L, 13, 0
int inByte = Bluetooth.read();
switch(inByte)
case 'L':
String str = Bluetooth.readString();
setpin(str.substring(0).toInt(), str.substring(1).toInt());
break;
void setpin(int BTinteger,int BTsetting){
digitalWrite(BTinteger, BTsetting);
}
But I really dont know how to do it?
Best to serial.print the string you've read so you can see if your substring calls make sense. I don't think they do though because what you likely have is this:
, 13, 0
So to get the pin number you would want a substring starting at 2.
int inByte = Bluetooth.read();
Not related to your problem, but why is your variable named as if it is a byte when it is declared as an int and used to read a char ?
Is it possible to do a:
SEND: L,13,1
"char,int,string" whatever = Bluetooth.read();
switch(whatever)
case "L"
setpin(str.substring(0), str.substring(1));
void setpin(int BTinteger,int BTsetting){
digitalWrite(BTinteger, BTsetting);
}
Hope you understand what i am trying to do?
This is the place where I have been working my code from.
But I can still not see the solution, sorry.
jokerper:
This is the place where I have been working my code from.
Are you referring to the Serial Input Basics thread? Then there is no need for the use of String (capital S). Look at the 2nd or 3rd example. There is also an example how to parse a comma separated text and how to convert text to a number.
i think I got it work, tested fine...
str = Bluetooth.readStringUntil('>');
switch (String(str).toInt()) {
case 1: setpin(1); Bluetooth.println("1"); break;
ect.