Start a new topic

please help

my code is recognizing button press on my nextion display, however it is not adjusting the LED brightness. anyone know what i'm missing?

here is my code:


#include <NexButton.h>

 

#include <NexTouch.h>

 

int barup = 8;

int bardown = 9;

NexButton bup = NexButton(4, 8, "bup");

NexButton bdown = NexButton(4, 9, "bdown");

char buffer[100] = {0};

 

// variables will change:

int brightness = 5;

int fadeAmount = 1;

 

NexTouch *nex_Listen_List[] =

{

    &bup,

    &bdown,

    NULL,

};

 

void bupPopCallback(void *ptr)

{

    NexButton *btn = (NexButton *)ptr;

    memset(buffer, 0, sizeof(buffer));

    if (strcmp(buffer,"ON"))

    {

    digitalWrite(barup,HIGH);

    brightness = brightness + fadeAmount;

    }

}

void bdownPopCallback(void *ptr)

{

   NexButton *btn = (NexButton *)ptr;

    memset(buffer, 0, sizeof(buffer));

    btn->getText(buffer, sizeof(buffer));

    if (strcmp(buffer,"ON"))

    {

        digitalWrite(barup, HIGH);

        strcpy(buffer, "ON");

    }

    else

    {

        digitalWrite(barup, LOW);

        strcpy(buffer, "OFF");

    }

    btn->setText(buffer);

   

}

 

void setup()

{

  nexInit();

  bup.attachPop(bupPopCallback, &bup);

  bdown.attachPop(bdownPopCallback, &bdown);

  pinMode(barup, OUTPUT);

  pinMode(bardown, OUTPUT);

  Serial.begin(9600);

  digitalWrite(8, LOW);

  digitalWrite(9, LOW);

  pinMode(barup, INPUT);

  pinMode(bardown, INPUT);

}

 

void loop()

{

  nexLoop(nex_Listen_List);

if(barup == HIGH)

{

  analogWrite(barup,brightness);

  brightness = brightness - fadeAmount;

  }

}

 

 



I don't think cut copy and pasting is helping your understanding.

So if buttons from Nextion are working ...

 this isn't a Nextion issue.  No?  How to code or electronics issue.



Read your code you presented.

Ponder how that was expected to do what you wanted.

Login or Signup to post a comment