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;
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.
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.
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.
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.
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?
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".