Nextion button how to run a function

Hi guys
I am a noob in arduino
now i want to write a simple code to control LED from nextion

#include "NexButton.h"
#include "NexText.h"

NexButton b0 = NexButton(0, 1, "b0");

char buffer[100] = {0};

NexTouch *nex_Listen_List =


  • Button to return the response.
  • @param ptr - the parameter was transmitted to pop event function pointer.

void b0PopCallback(void *ptr)
NexButton *btn = (NexButton *)ptr;
memset(buffer, 0, sizeof(buffer));
btn->getText(buffer, sizeof(buffer));
if (strcmp(buffer,"ON"))
strcpy(buffer, "ON");
digitalWrite(13, LOW);
strcpy(buffer, "OFF");


void setup(void)
b0.attachPop(b0PopCallback, &b0);

//setting port OUTPUT
pinMode(13, OUTPUT);

digitalWrite(13, LOW);


void loop(void)


void aaa() {
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for a second

I use button source code from here

I don't know why "aaa" can't run well
could somebody teach me how to put function in that.

sorry for my poor English

Did you get the original example to toggle an LED before modifying it?

I don't know why "aaa" can't run well

Can you explain more on what does and does not work?

You're using code to read a button's label and if it is "ON" then you QUICKLY toggle an LED

delay(100);                       // wait for a second

This will only flash the LED for 1/10th of a second, not a whole second. Perhaps too short for debugging purposes.