Reading 2 values from Serial Buffer

Hi
I was wondering if anyone could look at my code and see if there is a way to read the x value from my accelerometer into 1 text box and the y value into another text box simultaneously as I have coded below or is this not possible from serial buffer?

[void loop() // Main code here, to run repeatedly:
{
nexLoop(nex_listen_list);

int x = analogRead(ypin); //read from ypin
int y = analogRead(ypin); //read from ypin

float zero_G = 512.0; //ADC is 0~1023 the zero g output equal to Vs/2
float scale = 102.3; //ADXL335330 Sensitivity is 330mv/g
float accel_x = ((float)x - 331.5) / 65 * 9.8; //print x value on serial monitor
float accel_y = ((float)y - 329.5) / 68.5 * 9.8;

Serial.print(accel_y);
Serial.write('\n');
Serial.print(accel_x);

char buffer[6];

dtostrf(accel_y, 1, 0, buffer);
Uphill.setText(buffer);

dtostrf(accel_x, 1, 0, buffer);
LeftToRight.setText(buffer);

delay(300);

}]

Many Thanks
Andy

if there is a way to read the x value from my accelerometer into 1 text box

No. You can't read text into a text box. You have to write text to a text box.

  int x = analogRead(ypin);  //read from ypin
  int y = analogRead(ypin);  //read from ypin

Why are you reading the same pin twice, calling the value two different things?

Hi Paul

Sorry that is a typo error should be x pin. The results are displayed in a 2 different text box's. This is to display the angles of a platform. I am trying to read and display the x angle into 1 text box and the y angle into another box. Not great at explaining but hopefully its understandable.

Thanks

andyturner:
I am trying to read and display the x angle into 1 text box and the y angle into another box. Not great at explaining but hopefully its understandable.

Are you referring to '1 text box' and 'another text box' in the Serial Monitor? In Serial Monitor (see figure below), we have 'only one InputBox' to enter characters from Keyboard and 'only one OutputBox' to display characters received via USB/VUART Port.
SerialMonitor.png

SerialMonitor.png

Hi

No I am reading an accelerometer using a mega and trying to dsiplay the x reading into a text box on a nextion and y reading into another text box on the nextion display.

Thanks

Post your code, not just the loop function. In code tags please.

andyturner:
No I am reading an accelerometer using a mega and trying to dsiplay the x reading into a text box on a nextion and y reading into another text box on the nextion display.

Excellent clarification which is not there in the short text description of your original post.

Hi

I had looked at just creating events and calling them from individual button press but would quite like to display the value when the platform is level. As the code contains more than 9000 characters I will have to attach it I think?

Thanks

Hi

As the code is over 9000 characters I have had to attach it.

Thanks
Andy

PuttMasterFinalcopy.ino (28.2 KB)

PuttMasterFinalcopy.ino (28.2 KB)

I'm not sure what the issue is.

I see use of the setText method in b2PushCallback to write into a text box. I'd expect that you can do that in loop too, although you might want to control how often you do it using millis or it'll likely be an unreadable flickering mess.

I don't know if it matters, but I note that in the constructors for your text boxes, likely due to a copy paste error, you have called all of them "t0".