How to split numbers in the arduino code?

I'm hav ing some problems on separating numbers that I recived from my app inventor using the hc-06 bluetooth module.

here is my code in arduino:

void setup() {
Serial.begin(9600);
}

void loop()
{
String readString;
int delimiter, delimiter_1, delimiter_2, delimiter_3, delimiter_4, delimiter_5, delimiter_6, delimiter_7;

if (Serial.available() > 0)
{
readString = Serial.read();

delimiter = readString.indexOf("59");
delimiter_1 = readString.indexOf("59", delimiter + 1); // this 59 is equal the ";" on the app inventor
delimiter_2 = readString.indexOf("59", delimiter_1 + 1);
delimiter_3 = readString.indexOf("59", delimiter_2 + 1);
delimiter_4 = readString.indexOf("59", delimiter_3 + 1);
delimiter_5 = readString.indexOf("59", delimiter_4 + 1);
delimiter_6 = readString.indexOf("59", delimiter_5 + 1);

int a = readString.substring(delimiter + 1, delimiter_1).toInt();
int b = readString.substring(delimiter_1 + 1, delimiter_2).toInt();
int c = readString.substring(delimiter_2 + 1, delimiter_3).toInt();
int d = readString.substring(delimiter_3 + 1, delimiter_4).toInt();
int e = readString.substring(delimiter_4 + 1, delimiter_5).toInt();
int f = readString.substring(delimiter_5 + 1, delimiter_6).toInt();

Serial.println(f);

}
}

here is my code in app inventor

image

So my problem is the app inventor sends everything together, and I need to split them, but I don't know how to do this.

If someone knows, please help me!

Serial.read returns a single int.
Not a whole String.

Please remember to use code tags when posting code

Doesn't it return a char, a byte?

No, it doesn't, it returns an int.
Easy enough to check.

Oh. A surprise to me. I'll have to check for char sgn = Serial.read in my old codes.

It's a legacy feature. It's an int so a -1 code can be returned as an error condition. You can continue to ignore it and assign to a char type at will, since you already checked the "unavailable" condition with available().

Take a short look at the beginning of loop(). Char Sa compiles without remarks.

[code]
void setup() {
  // put your setup code here, to run once:
  pinMode (9, OUTPUT);//blue colour
  pinMode (10, OUTPUT);//red colour
  pinMode (11, OUTPUT);//green coour
  Serial.begin(115200);
  analogWrite(9, 125);//turn on blue colour
  Serial.print("125 ");//ijkltell on Serial
  delay(5000);//give spectator time to verify function
  analogWrite(9, 0);//turn off blue
  analogWrite(10, 125);//turn on red
  Serial.print("125 ");//tell on Serial
  delay(5000);//give spectator time to verify function
  analogWrite(10, 0);//turn of red
  analogWrite(11, 125);//turn on green
  Serial.println("125 ");//tell on Serial
  delay(5000);//give spectator time to verify function
  analogWrite(11, 0);//turn off green
}

void loop() {
  int i, j, k;//the three colour loop varibles
  int debugDisplay;//value to be displyed if defined name is given
  bool debugFlag;//debug flag telling valid variable is received
  char Sa;//debugged variable name to be displayed

  for ( i = 0; i < 25; i = i + 1)//loop for blue
  {
    for ( j = 0; j < 25; j = j + 1)//loop for red
    {
      for ( k = 0; k < 25; k = k + 1)//loop for green
      {
        debugFlag = false;//initiate flag for displaying value
        if (Serial.available())//if debug order from keyboard
        {
          Sa = Serial.read();//get the name for variable to disply
          switch (Sa) {
            case 'A'://name is 'A', display its variable in switch case below
              {
                debugDisplay = i;//display correct variable value in case below
                debugFlag = true;//tell valid debug name was received
                break;
              }
            case 'B'://name is 'B', display its variable in switch case below
              {
                debugDisplay = j;//display correct variable in case below
                debugFlag = true;//tell valid debug name was received
                break;
              }
            case 'C'://name is 'C', display its variable in switch case below
              {
                debugDisplay = k; //display correct variable in case below
                debugFlag = true;//tell valid debug name was received
              }
            default:
              //              debugFlag = false;
              break;
          }//end of switch

          if (debugFlag)//print out if valid debug from Serial
          {
            Serial.print(Sa); Serial.print(" = ");//name of variable
            Serial.println(debugDisplay);// actual variable value
            debugFlag = false;//turn off display, vslue displeyd above
          }
        }

        analogWrite(9, i);//PWM for blue
        analogWrite(10, j);//PWM for green
        analogWrite(11, k);//PWM for red
      }
    }
  }
  delay(20);
}
[/code]

Should give an "implicit narrowing" warning, I think.

It didn't! I wide opened the the error window and found no remarks what so ever. Only the memory usage!

I guess for Arduino, enabling the compiler's "-Wconversion" option would open up a massive can of worms. :roll_eyes:

The version, the setup is what I got when downloaded the IDE. No adjustments made by me.

int value = Serial.parseInt();will throw away characters until it finds something that looks like a number, then accept characters until it finds one that doesn't look like a number or times out (1 second), then returns the value of the number. Call it once for each number you expect to receive.

I'm writing to add some information for my doubt in order to be more informative.

So my problem is that I need to slip the numbers that I receive from the app inventor. The app sends to my serial , for example, the numbers 1,2,3,4,5,6. I created a variable (INT) for A,B,C,D,E,F; and I want to split each letter for each number. Then I print some letter, (A), and the results have to be the first number, in this case number 1.
I’ve already created a program, but it doesn't work, because when I print some letter (A), it shows me all the numbers (1,2,3,4,5,6).
In app inventor I put a semicolon between the textbox (numbers) trying to split them, and make the program easier in arduino code, but when I send the number with the semicolon, the same appears as a number 59. As a result, the serial shows this: 59,1,59,2,59,3,59,4,59,5,59,6.

what I need to do?

I already sent my app inventor blocks and the arduino code, but to add, here is my designer from the app:
image

And, to show what is happening, here is my Serial, from arduino.

I hope that this information could be helpful to solve my problem.

And, to show what is happening, here is my Serial, from arduino.

image