Cannot print string to int (or something like this)

Hi, I know i dont have to parse the data in this case, but when i want to extract more data from Serial.read string, i must. Now when I want to print the data it says

exit status 1
no matching function for call to 'println(int (&)(String))'

when I use it like this

String rread = "R0";
void setup(){
  Serial.begin(9600);
}
int parseData(String rread){
  rread.remove(0,1);
  return rread.toInt();
}
void loop(){
  Serial.println(parseData);
}

It doesnt even work when i put it into switch.

String rread = "R0";
void setup(){
  Serial.begin(9600);
}
int parseData(String rread){
  rread.remove(0,1);
  return rread.toInt();
}
void loop(){
  switch(parseData){
    case 0:
      digitalWrite(2,0)
      break;
    case 1:
      digitalWrite(2,1)
      break;
  }
}

This is the error message:

exit status 1
switch quantity not an integer

Also it doesnt work when use it in if statement

String rread = "R0";
void setup(){
  Serial.begin(9600);
}
int parseData(String rread){
  rread.remove(0,1);
  return rread.toInt();
}
void loop(){
  if (parseData = 1){
    digitalWrite(2,1);
  } else {
    digitalWrite(2,0);
  }
}

This is the error message:

exit status 1
assignment of function 'int parseData(String)'

I also tried changing the "1" to a string in the if statement

String rread = "R0";
void setup(){
  Serial.begin(9600);
}
int parseData(String rread){
  rread.remove(0,1);
  return rread.toInt();
}
void loop(){
  if (parseData = "1"){
    digitalWrite(2,1);
  } else {
    digitalWrite(2,0);
  }
}

But with no success

exit status 1
assignment of function 'int parseData(String)'

Thank you for answers.

  Serial.println(parseData);

You are not passing a parameter to the parseData() function

UKHeliBob:

  Serial.println(parseData);

You are not passing a parameter to the parseData() function

Sorryy but I dont quite get you.

parseData requires a String parameter

int parseData(String rread){

You told the compiler that you would supply a String to work with and that inside the function its name would be rread but you did not send a String to the function. Note, this is NOT the same variable as the one that you declared at the top of the program despite the fact that it's name is the same. Read up on variable scope in C

Try this

String rread = "R0";
void setup()
{
  Serial.begin(9600);
}

int parseData(String rread)
{
  rread.remove(0, 1);
  return rread.toInt();
}
void loop()
{
  Serial.println(parseData( rread));
}

Alternatively you could not send a String, in which case the function will use the global one declared at the top of the program

String rread = "R0";
void setup()
{
  Serial.begin(9600);
}

int parseData()
{
  rread.remove(0, 1);
  return rread.toInt();
}
void loop()
{
  Serial.println(parseData());
}

What you can't do is to mix the two

Note that a function call must always have the () at the end of the function name even if no variables are being passed to the function

TheMemberFormerlyKnownAsAWOL:
parseData requires a String parameter

When I do

Serial.println(parseData(String s))

UKHeliBob:

int parseData(String rread){

You told the compiler that you would supply a String to work with and that inside the function its name would be rread but you did not send a String to the function. Note, this is NOT the same variable as the one that you declared at the top of the program despite the fact that it's name is the same. Read up on variable scope in C

Try this

String rread = "R0";

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

int parseData(String rread)
{
 rread.remove(0, 1);
 return rread.toInt();
}
void loop()
{
 Serial.println(parseData( rread));
}




Alternatively you could not send a String, in which case the function will use the global one declared at the top of the program


String rread = "R0";
void setup()
{
 Serial.begin(9600);
}

int parseData()
{
 rread.remove(0, 1);
 return rread.toInt();
}
void loop()
{
 Serial.println(parseData());
}




What you can't do is to mix the two

Note that a function call must always have the () at the end of the function name even if no variables are being passed to the function

Wow ok thank you so much, but how is it not the same one and why it requires it (how to make it to not require it) because the second code of yours doesnt work for me, it says

exit status 1
too few arguments to function 'int parseData(String)'

(Sorry for being so stupid to not understand this)

RaterHraje_:
When I do

Serial.println(parseData(String s))

Wow ok thank you so much, but how is it not the same one and why it requires it (how to make it to not require it) because the second code of yours doesnt work for me, it says

exit status 1

too few arguments to function 'int parseData(String)'



(Sorry for being so stupid to not understand this)

Nevermind it does work, thank you for your patience.

how is it not the same one

As I suggested

Read up on variable scope in C