Hello, I wanted to ask a question. In the following sketch made in arduino, to separate data, I want to get all the data that is characterized by the ",", because as the sketch is, I only get the first value.
That is, I want to get the 133 365 4 12… and so on
Your string split appears to contain two separator characters, that is ',' and '/'.
The function call in the loop() getValue( split, ',', 0) appears, because of the fixed parameter 0, to always return the first substring from split.
I have made this arrangement, but I need what I said before, that the index parameter is not fixed, if not, I will get values that contain a certain character "," or "/".
I understand how you do it, but placing too many Serial.prints is tedious for me, since I am going to receive hundreds of data. That's why I need all data containing "," to be readable
What about changing the 0 to an x and using a for loop to change the value of x ?
Edit
Even if that works, you'll get another mess because you are not handing the delimiter '/'.
The next substring to be returned will be '215/365' which will fail to convert to an integer.
Well I explain better, I am doing a project, in which I have several sensors connected to an arduino, this data is being sent to another Arduino by serial port, but what I want is that every time the data arrives, just take the data from a certain sensor, and so with the other take only the values of this sensor. That is, I want to extract the data received from the sensors. I hope to make myself understood.
In the following image you can see integer values (light sensor) and decimal values (acceleration sensor), so I only want to take the values of the light sensor in one variable, and the acceleration sensor in another variable, for later , to be able to put these data to use.
I've been finding out how to do it, but I can't find the way to do it, I've seen that it can be done with the string class, but I don't know how to do it precisely.
Similar to post #15 :
Each time you get data from a sensor, send a line terminated with an end of line character. That line should consist of the sensor identifier and the value that sensor returns.
Say:
S01 13.98
S03 5.0
S02 87.9
. . .
If you really want to pack it all in a string then look at json.
In order to make myself understand better, in the following image, the obtaining of values from the sensors is better observed.
What I want is to separate the luminosity and acceleration sensor data into different variables.
If there is new data in the serial buffer then read the first 5 characters.
If those 5 characters are 'Ace: ' then set your acceleration variable to the result of Serial.parseFloat()
If those 5 characters are 'Lum: ' then set your luminosity variable to the result of Serial.parseInt()