Arduino does not have a split function like Processing does, SO, you need to make your own split function.
Here is something I made to help me. this will take in 3 values and change them to ints.
#include<string.h>
int X,Y,State,currentCommand=0;
String x,y,state;
// LED connected to pin 13 (on-board LED)
byte ledpin = 13;
void setup()
{
pinMode(ledpin, OUTPUT);
Serial.begin(9600); // start serial communication at 9600bps
}
void loop() {
if( Serial.available()) // if data is available to read
{
digitalWrite(ledpin, HIGH); //if data is being entered
char val= Serial.read();
if (val == ','){
currentCommand++;
}
else {
switch (currentCommand) { //add more case statements for more data
case 0:
x += val; //stores as a string
val = ' '; //clear for new char
break;
case 1:
y += val; //stores as a string
val = ' ';
break;
case 2: //gets the last data
state += val; //stores as a string
val = ' ';
currentCommand = 0; // this only allows one char to be saved here, modify to save more.
X=x.toInt(); //delete .toInt() if needed
Y=y.toInt(); //delete .toInt() if needed
State = state.toInt(); //delete .toInt() if needed
//shows what you entered
Serial.print(X);
Serial.print(", ");
Serial.print(Y);
Serial.print(", ");
Serial.println(State);
x="";y="";state=""; //clear values
X=0;Y=0;State=0; //clear values
break;
}
}
}
digitalWrite(ledpin, LOW);
}
alva:
Yes... But it doesnt work correctly. And i can't trace the error because i confused with the sintax.
maybe someone can help me with the other ways?
Maybe you can tell us (1) what you're doing already (i.e., show us your code), (2) what you expect it to do, (3) what it's actually doing, and (4) what errors you're getting?