#include "Nextion.h"
const int led1 = 2;

// Declare your Nextion objects - Example (page id = 0, component id = 1, component name = "b0")
NexText tBatPerc  = NexText(1, 11, "tBatPerc");
NexButton bUpload = NexButton(1, 3, "bUpload");

// Register a button object to the touch event list.
NexTouch *nex_listen_list[] = {
  &bUpload,
  NULL
};

/*
   Button bOn component pop callback function.
   When the ON button is released, the LED turns on and the state text changes.
*/
void bUploadPopCallback(void *ptr) {
  tBatPerc.setText("On");
  digitalWrite(led1, HIGH);
}

void setup() {
  Serial.begin(9600);

  nexInit();

  // Register the pop event callback function of the components
  bUpload.attachPop(bUploadPopCallback, &bUpload);

  pinMode(led1, OUTPUT);

}

void loop() {
  nexLoop(nex_listen_list);
}
