Help with my Arduino project.

Hey, fellas.

I have a problem with the code at the moment of uploading or compiling.

#include<Servo.h>

Servo serX;
Servo serY;

String serialData;

void setup (){

     //Remember to switch pins

 serX.attach(10);
 serY.attach(9);
 Serial.begin(9600);
 Serial.setTimeout(10);

 String serialData;
}
void loop (){
  //No use.
}


void serialEvent(){
  
  serialData = Serial.readString;

  serX.write(parseDataX(serialData));
  serY.write(parseDataY(serialData));
}

int parseDataX(String data){
  data.remove(data.indexOf("Y"));
  data.remove(data.indexOf("X"), 1);

  return.data.toInt();
}

int parseDataY(String data){
  data.remove(0, data.indexOf("Y") + 1);

  return data.toInt();
}

Error messages:

Arduino: 1.8.7 Hourly Build 2018/10/24 04:33 (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\bleh\Documents\Arduino\sketch_nov01b\sketch_nov01b.ino: In function 'void serialEvent()':

sketch_nov01b:26:14: error: invalid use of non-static member function

serialData = Serial.readString;

^

C:\Users\bleh\Documents\Arduino\sketch_nov01b\sketch_nov01b.ino: In function 'int parseDataX(String)':

sketch_nov01b:36:9: error: expected primary-expression before '.' token

return.data.toInt();

^

exit status 1
invalid use of non-static member function

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

serialData = Serial.readString();

connorboi:
sketch_nov01b:36:9: error: expected primary-expression before '.' token

return.data.toInt();

^

Did you maybe mean to write:

return data.toInt();

Yeah, I got the return wrong too. Thanks for noticing it!

But the serial keeps giving me problems.

I'm a newbie, I just know code basics.

I really didn't understand a thing in the OO link.

Please explain what you mean by "giving me problems".

I mean, the same error keeps popping.

At this point, I don't know what to try.

If you can understand the code, maybe you can give me another function I could use.

If you're getting the same exact error then you didn't make the change PaulMurrayCbr recommended.

I really didn't understand, to be honest.

I'm a newbie at this, and even reading over and over again I still don't understand, sorry for being a bother. :confused:

Your code :

serialData = Serial.readString;

Suggested code :

serialData = Serial.readString();

I'm actually quite disappointed that it was so easy to fix.

Thank you so much, now I can upload my code to the board. :slight_smile:

I feel really dumb right now.

connorboi:
The topic is closed, thank you all for helping me out!