I have a solid question for you guys, i'm searching the answer from two weeks.
I created an android app with 8 buttons and 4 sliders. I made it to control a led stripe (WS2812B) using a bluetooth module (HC-05).
The values of the sliders:
3 from 0-255
1 from 0-100.
Every buttons send a single character like A,B,C... .
The 3 sliders with 0-255 values are my RGB channels and they are sending text with this syntax:
' X.Rvalue.Gvalue.Bvalue ' .
The last one sliders is the led stripe brightness with 0-100 min and max value and it is sending text with this syntax: ' Z.Lvalue ' .
Ok, now, I stated as char the variable that contains BT.read() value, so i know i have to convert the char data back to byte data with ' atoi ' function.
Finally, the question is, how can i differentiate the sliders data coming into the bt serial?
How can i separate the data coming from different sliders?
I send ' X. ' because i see on internet someone differentiate the data coming from one slider with the letter, like X or Z, before the actual data that i need, all using strings, and using dots as separators.
And after that how can i store that part of string into my variable?
Like my Rvalue, Gvalue and Bvalue even in char because atoi can convert it easily.
After that i can assign the RGB value to my led stripe.
I'm using two libraries: <FastLED.h> and <SofwareSerial.h>
Thanks, it's so hard to combine all of that
P.S. : I solved the use of the buttons with a switch case.
The RGB values and your slider values are all single bytes.
So just send them over bluetooth as sequential byte values - R value, G value, B value, slider 1 value, slider 2 value.
You could also precede these by an arbitrary ASCII code, e.g. the '~' character, to indicate to your received the start of transmission. Where upon the received would expect there to be 5 byte values to follow.
You said that you are sending something like "X.34.67.129". If you wanted full saturation on all colors, you'd send "X.255.255.255". I'm willing to be that you can count to 13 without taking your shoes off. So, a fixed size (16 element) char array would be more than adequate for holding all characters sent. There is NO reason to piss away resources using the String class.
Sending data like that doesn't make a lot of sense. When the brightness slider moves, you send "Z.nnn", where nnn is the numeric value.
When the red slider moves, why not send "Rnnn!", where nnn is the numeric value? Why send all three slider's values? When the green slider moves, send "Gnnn!" and when the blue slider moves, send "Bnnn!".
That way, there is nothing complicated to parse. Just read the data. If the character is a R, a G, a B or a Z, store the next few bytes until the ! arrives, appending a NULL after each character is saved. When the ! arrives, call atoi() with the array you saved the data in, and store the resulting in wherever makes sense based on the letter that preceded the numeric representation. See Robin2's tutorial on serial data: http://forum.arduino.cc/index.php?topic=396450.0