Read Data from Nextion Display and assign it to a Variable

Hi everyone, I'm using a ESP32, and I'm trying to read data from the Nextion display.
I've created a "Lift Angle Function" with a default value set to 52 and with the "Button Minus Function" and "Button Plus Function" I can increase or decrease that default value. After increasing or decreasing 52, in the "Button Enter Function" I want to assign the new value to the variable int lift_angle. My question is how do I do that?
I've written there int lift_angle = get LiftAngle;, what's the right syntax


#include <Nextion.h>


/********************************************************************
   Nextion Function
 ********************************************************************/
void ButtonMinusPushCallBack(void *ptr);
void ButtonPlusPushCallBack(void *ptr);
void ButtonWeiterPushCallBack(void *ptr);
void ButtonEnterPushCallBack(void *ptr);
void ButtonClosePushCallBack(void *ptr);
void LiftAnglePushCallBack(void *ptr);

/********************************************************************
   Nextion component for page0
 ********************************************************************/
NexButton ButtonWeiter = NexButton(0, 1, "ButtonWeiter");  

/********************************************************************
   Nextion component for page1
 ********************************************************************/
NexText LiftAngle =   NexText(1, 1, "LiftAngle");  
NexButton ButtonMinus = NexButton(1, 2, "ButtonMinus");  
NexButton ButtonPlus =  NexButton(1, 3, "ButtonPlus");  
NexButton ButtonEnter = NexButton(1, 4, "ButtonEnter");  

/********************************************************************
   Nextion component for page2
 ********************************************************************/
NexButton ButtonClose = NexButton(2, 1, "ButtonClose"); 
NexText Rate =        NexText(2, 2, "Rate");  
NexText Amplitude =   NexText(2, 3, "Amplitude"); 
NexText BeatError =   NexText(2, 4, "BeatError");  
NexText BeatRate =    NexText(2, 5, "BeatRate");   

/********************************************************************
   Nextion screens
 ********************************************************************/
NexPage zero = NexPage(0, 0, "zero");
NexPage one = NexPage(1, 0, "one");
NexPage two = NexPage(2, 0, "two");

/********************************************************************
   Buffer zone of various variables
 ********************************************************************/
char buffer[100] = {0};
char buffer_Rate[10] = {0};
char buffer_Amplitude[10] = {0};
char buffer_BeatError[10] = {0};
char buffer_BeatRate[10] = {0};
char buffer_LiftAngle[10] = {0};

NexTouch *nex_listen_list[] =
{
  &ButtonClose,
  &ButtonEnter,
  &ButtonPlus,
  &ButtonMinus,
  &ButtonWeiter,
  &LiftAngle,
  NULL
};

/********************************************************************
   Lift Angle Function
 ********************************************************************/
void LiftAnglePushCallBack(void *ptr)
{
  dbSerialPrintln("LiftAnglePushCallBack");
  LiftAngle.setText("52");
}

/********************************************************************
   Button Minus Function
 ********************************************************************/
void ButtonMinusPushCallBack(void *ptr)  
{
  uint16_t len;
  uint16_t number;
  dbSerialPrintln("ButtonMinusPushCallBack");
  
  memset(buffer, 0, sizeof(buffer));
  LiftAngle.getText(buffer, sizeof(buffer));
    
  number = atoi(buffer);
  number -= 1;

  memset(buffer, 0, sizeof(buffer));
  itoa(number, buffer, 10);
    
  LiftAngle.setText(buffer);
}

/********************************************************************
   Button Plus Function
 ********************************************************************/
void ButtonPlusPushCallBack(void *ptr) 
{
  uint16_t len;
  uint16_t number;
  dbSerialPrintln("ButtonPlusPushCallBack");
  
  memset(buffer, 0, sizeof(buffer));
  LiftAngle.getText(buffer, sizeof(buffer));
    
  number = atoi(buffer);
  number += 1;

  memset(buffer, 0, sizeof(buffer));
  itoa(number, buffer, 10);
    
  LiftAngle.setText(buffer);
}

/********************************************************************
   Button Weiter Function
 ********************************************************************/
void ButtonWeiterPushCallBack(void *ptr)   
{
  dbSerialPrintln("ButtonWeiterPushCallBack");
  Serial.print("page one");
  Serial.write(0xff);  
  Serial.write(0xff);
  Serial.write(0xff); 
}

/********************************************************************
   Button Enter Function
 ********************************************************************/
void ButtonEnterPushCallBack(void *ptr) 
{
  int time_elapsed = (start_time - end_time)/1000;
  float Rate = (count/time_elapsed*10)*24*3600;               //Beat rate per day
  float BeatError = (start_time - end_time)/10;               //Divided by 10 because we using 10 beats
  int lift_time = (start_time-end_time)/3*1000;               //Divided by 3 becuase we want to calculate time between first and third tick 
  int lift_angle = get LiftAngle;
  float Amplitude = lift_angle / (2 * sin(180 * lift_time * Rate / 7200));
  float BeatRate = 36600;                   //per hour
  float Frequency = BeatRate / 3600;
  dbSerialPrintln("ButtonEnterPushCallBack");
  Serial.print("page two");
  Serial.print("Rate.txt=");
  Serial.print(Rate);
  Serial.print("Amplitude.txt=");
  Serial.print(Amplitude);
  Serial.print("BeatError.txt=");
  Serial.print(BeatError);
  Serial.print("BeatRate.txt=");
  Serial.print(BeatRate);
  Serial.write(0xff);  
  Serial.write(0xff);
  Serial.write(0xff);
}

/********************************************************************
   Button Close Function
 ********************************************************************/
void ButtonClosePushCallBack(void *ptr) 
{
  dbSerialPrintln("ButtonClosePushCallBack");
  Serial.print("page one");
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
}

void setup(void)
{
  nexInit();
 
/********************************************************************
   Register all event callback function of all component.
 ********************************************************************/
  LiftAngle.PushCallBack(LiftAnglePushCallBack);
  ButtonPlus.attachPush(ButtonPlusPushCallBack);
  ButtonMinus.attachPush(ButtonMinusPushCallBack);
  ButtonEnter.attachPush(ButtonEnterPushCallBack);
  ButtonClose.attachPush(ButtonClosePushCallBack);
  ButtonWeiter.attachPush(ButtonWeiterPushCallBack);
  dbSerialPrintln("Setup done");
}

void loop(void)
{
  nexLoop(nex_listen_list);
}

You have got the value in your number variable. You could assign it to your new variable.

Still have an error.
'number' was not declared in this scope

Number only exists in the callback functions. I suspect that you tried to use it elsewhere.

Nowhere else, I've used it only in the Button Minus and Plus Function

Post your code.

Here it is

//#include <SoftwareSerial.h>
#include <Nextion.h>
#include <filters.h>                                    
#include <SPI.h>    
#define SS 5                               


/********************************************************************
   Filter Setting, LPF
 ********************************************************************/
const float cutoff_freq   = 125.0;                /* Cutoff frequency in Hz */
const float sampling_time = 0.001;                /* Sampling time in seconds. */
IIR::ORDER  order  = IIR::ORDER::OD4;             /* Order (OD1 to OD4) */
Filter f(cutoff_freq, sampling_time, order);


/********************************************************************
   Variables
 ********************************************************************/
int n = 0;
int count = 0;
int start_time;
int end_time;
const unsigned long event = 5000;


/********************************************************************
   Nextion Function
 ********************************************************************/
void ButtonMinusPushCallBack(void *ptr);
void ButtonPlusPushCallBack(void *ptr);
void ButtonWeiterPushCallBack(void *ptr);
void ButtonEnterPushCallBack(void *ptr);
void ButtonClosePushCallBack(void *ptr);
void LiftAnglePushCallBack(void *ptr);


/********************************************************************
   Nextion component for page0
 ********************************************************************/
NexButton ButtonWeiter = NexButton(0, 1, "ButtonWeiter");  


/********************************************************************
   Nextion component for page1
 ********************************************************************/
NexText LiftAngle =   NexText(1, 1, "LiftAngle");  
NexButton ButtonMinus = NexButton(1, 2, "ButtonMinus");  
NexButton ButtonPlus =  NexButton(1, 3, "ButtonPlus");  
NexButton ButtonEnter = NexButton(1, 4, "ButtonEnter");  


/********************************************************************
   Nextion component for page2
 ********************************************************************/
NexButton ButtonClose = NexButton(2, 1, "ButtonClose"); 
NexText Rate =        NexText(2, 2, "Rate");  
NexText Amplitude =   NexText(2, 3, "Amplitude"); 
NexText BeatError =   NexText(2, 4, "BeatError");  
NexText BeatRate =    NexText(2, 5, "BeatRate");   


/********************************************************************
   Nextion screens
 ********************************************************************/
NexPage zero = NexPage(0, 0, "zero");
NexPage one = NexPage(1, 0, "one");
NexPage two = NexPage(2, 0, "two");

/********************************************************************
   Buffer zone of various variables
 ********************************************************************/
char buffer[100] = {0};
char buffer_Rate[10] = {0};
char buffer_Amplitude[10] = {0};
char buffer_BeatError[10] = {0};
char buffer_BeatRate[10] = {0};
char buffer_LiftAngle[10] = {0};


NexTouch *nex_listen_list[] =
{
  &ButtonClose,
  &ButtonEnter,
  &ButtonPlus,
  &ButtonMinus,
  &ButtonWeiter,
  &LiftAngle,
  NULL
};


/********************************************************************
   Lift Angle Function
 ********************************************************************/
void LiftAnglePushCallBack(void *ptr)
{
  dbSerialPrintln("LiftAnglePushCallBack");
  LiftAngle.setText("52");
}


/********************************************************************
   Button Minus Function
 ********************************************************************/
void ButtonMinusPushCallBack(void *ptr)  
{
  uint16_t len;
  uint16_t number;
  dbSerialPrintln("ButtonMinusPushCallBack");
  
  memset(buffer, 0, sizeof(buffer));
  LiftAngle.getText(buffer, sizeof(buffer));
    
  number = atoi(buffer);
  number -= 1;

  memset(buffer, 0, sizeof(buffer));
  itoa(number, buffer, 10);
    
  LiftAngle.setText(buffer);
}


/********************************************************************
   Button Plus Function
 ********************************************************************/
void ButtonPlusPushCallBack(void *ptr) 
{
  uint16_t len;
  uint16_t number;
  dbSerialPrintln("ButtonPlusPushCallBack");
  
  memset(buffer, 0, sizeof(buffer));
  LiftAngle.getText(buffer, sizeof(buffer));
    
  number = atoi(buffer);
  number += 1;

  memset(buffer, 0, sizeof(buffer));
  itoa(number, buffer, 10);
    
  LiftAngle.setText(buffer);
}


/********************************************************************
   Button Weiter Function
 ********************************************************************/
void ButtonWeiterPushCallBack(void *ptr)   
{
  dbSerialPrintln("ButtonWeiterPushCallBack");
  Serial.print("page one");
  Serial.write(0xff);  
  Serial.write(0xff);
  Serial.write(0xff); 
}


/********************************************************************
   Button Enter Function
 ********************************************************************/
void ButtonEnterPushCallBack(void *ptr) 
{
  int time_elapsed = (start_time - end_time)/1000;
  float Rate = (count/time_elapsed*10)*24*3600;               //Beat rate per day
  float BeatError = (start_time - end_time)/10;               //Divided by 10 because we using 10 beats
  int lift_time = (start_time-end_time)/3*1000;               //Divided by 3 becuase we want to calculate time between first and third tick 
  uint16_t lift_angle = number;
  float Amplitude = lift_angle / (2 * sin(180 * lift_time * Rate / 7200));
  float BeatRate = 36600;                   //per hour
  float Frequency = BeatRate / 3600;
  dbSerialPrintln("ButtonEnterPushCallBack");
  Serial.print("page two");
  Serial.print("Rate.txt=");
  Serial.print(Rate);
  Serial.print("Amplitude.txt=");
  Serial.print(Amplitude);
  Serial.print("BeatError.txt=");
  Serial.print(BeatError);
  Serial.print("BeatRate.txt=");
  Serial.print(BeatRate);
  Serial.write(0xff);  
  Serial.write(0xff);
  Serial.write(0xff);
}


/********************************************************************
   Button Close Function
 ********************************************************************/
void ButtonClosePushCallBack(void *ptr) 
{
  dbSerialPrintln("ButtonClosePushCallBack");
  Serial.print("page one");
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
}


void setup(void)
{
  Serial.begin(9600);                     /* initialization of serial communication */
  SPI.begin();                            /* initialization of SPI port */
  SPI.setDataMode(SPI_MODE0);             /* configuration of SPI communication in mode 0 */
  SPI.setClockDivider(SPI_CLOCK_DIV64);   /* configuration of clock at 1MHz */
  pinMode(SS, OUTPUT);
  Serial.println("Start");
  nexInit();

  
/********************************************************************
   Register all event callback function of all component.
 ********************************************************************/
  LiftAngle.PushCallBack(LiftAnglePushCallBack);
  ButtonPlus.attachPush(ButtonPlusPushCallBack);
  ButtonMinus.attachPush(ButtonMinusPushCallBack);
  ButtonEnter.attachPush(ButtonEnterPushCallBack);
  ButtonClose.attachPush(ButtonClosePushCallBack);
  ButtonWeiter.attachPush(ButtonWeiterPushCallBack);
  dbSerialPrintln("Setup done");
}

void loop(void)
{  
  nexLoop(nex_listen_list);     /* When a pop or push event occured every time, the corresponding component[right page id and component id] in touch event list will be asked. */
  
  int16_t* samples;
  samples = (int16_t*)malloc(sizeof(int16_t)*100);
  if(millis()>event)
  {
    if(samples == NULL)
    {
      Serial.print("insufficient memory");
    }
    else
    {
      float filteredval = f.filterIn(MIC3_getSound());
      samples[n++] = filteredval;
            
    }
  }
  if(*samples>18000)
  {
    count++;
    start_time = millis();
    if(count>=10)
    {
      end_time = millis();
    }
  }
  /*int time_elapsed = (start_time - end_time)/1000;
  float Rate = (count/time_elapsed*10)*24*3600;               //Beat rate per day
  float BeatError = (start_time - end_time)/10;                              //Divided by 10 because we using 10 beats
  int lift_time = (start_time-end_time)/3*1000;               //Divided by 3 becuase we want to calculate time between first and third tick 
  int lift_angle = 52;
  float Amplitude = lift_angle / (2 * sin(180 * lift_time * Rate / 7200));
  float BeatRate = 36600;                   //per hour
  float Frequency = BeatRate / 3600;*/
  Serial.println(*samples);
  free(samples);
  n = 0;
}


int MIC3_getSound(void) {
  digitalWrite(SS, LOW);                                        //activate chip select
  int sound = SPI.transfer(0) | (SPI.transfer(0) << 8);         //reconstruct 12-bit data
  digitalWrite(SS, HIGH);                                       //deactivate chip select
  return sound;
}

It looks the same. Can you post the error it gives you?

C:\Users\Josia\Desktop\Ali Yasir\Zeitwaage\Zeitwaage.ino: In function 'void ButtonEnterPushCallBack(void*)':
Zeitwaage:169:25: error: 'number' was not declared in this scope
uint16_t lift_angle = number;
^
C:\Users\Josia\Desktop\Ali Yasir\Zeitwaage\Zeitwaage.ino: In function 'void setup()':
Zeitwaage:216:13: error: 'class NexText' has no member named 'PushCallBack'
LiftAngle.PushCallBack(LiftAnglePushCallBack);
^
At global scope:
cc1plus.exe: warning: unrecognized command line option '-Wno-frame-address'
exit status 1
'number' was not declared in this scope

Number is declared in ButtonPlusPushCallBack and ButtonMinusPushCallBack and is therefore only accessible there. You're trying to use it in ButtonEnterPushCallBack, hence the compiler's complaint.

It's not an ideal solution, but you can likely get it working by making number a global instead. Don't forget to remove the declarations you have now if you do this.

Thanks for the solution Wildbill.
Any idea about this ? I've change PushCallBack to PopCallBack

C:\Users\Josia\Desktop\Ali Yasir\Zeitwaage\Zeitwaage.ino: In function 'void setup()':
Zeitwaage:217:13: error: 'class NexText' has no member named 'PopCallBack'
LiftAngle.PopCallBack(LiftAnglePopCallBack);
^
At global scope:
cc1plus.exe: warning: unrecognized command line option '-Wno-frame-address'
exit status 1
'class NexText' has no member named 'PopCallBack'

If you change your code and need help with it, post it - trying to guess what you've done isn't really practical.

@barbess, do not cross-post.

Thread locked.