Start a new topic

Changing Between Modes 1 & 2.

Hi,


I have been trying to solve how to use the Nextion HMI, to change between modes 1 & 2. The aim is when mode 1 is pressed, it should toggle between mode 2, which will activate mode 1 to be on and mode 2 should be inactive which should be off. Vice vesa with mode 2, it should toggle between the two modes, depending which mode is pressed that mode should be active while the other mode is inactive. Using the HMI to toggle between the two modes using two buttons.


#include <Nextion.h>

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

uint8_t number = 0;

uint8_t mode1 = 1;
uint8_t mode2 = 1;

char buffer[10] = {0};
char buffer_b0[10] = {0};
char buffer_b1[10] = {0};

int8_t setmode_type = -1;

NexTouch *nex_Listen_List[] =
{
  &b0,
  &b1,
  NULL
};

void b0PopCallback(void *ptr)
{
  NexButton *btn = (NexButton *)ptr;
  memset(buffer, 0, sizeof(buffer));
  btn->getText(buffer, sizeof(buffer));
  if(strcmp(buffer,"ACTIVE"))
  {
  strcpy(buffer,"ACTIVE");
  }
  else
  {
  strcpy(buffer,"INACTIVE");
  }
  btn->setText(buffer);
}

void b1PopCallback(void *ptr)
{
  NexButton *btn = (NexButton *)ptr;
  memset(buffer, 0, sizeof(buffer));
  btn->getText(buffer, sizeof(buffer));
  if(strcmp(buffer,"ACTIVE"))
  {
  strcpy(buffer,"ACTIVE");
  }
  else
  {
  strcpy(buffer,"INACTIVE");
  }
  btn->setText(buffer);
}

void setup()
{
  dbSerial.print(9600);
  nexInit();

  b0.attachPop(b0PopCallback, &b0);
  b1.attachPop(b1PopCallback, &b1);

  dbSerial.println("setup done");
}

void loop()
{
  unsigned long nowtime = millis();
  unsigned long update = 1000;
 
  if(nowtime > update)
  {
  update += 1000;
  }
 
  nexLoop(nex_Listen_List);
}


I have attched my code, if anyone could help me to solve the problem, will appreciate the help. As I spent to much time and haven't an idea how to solve the problem.


Thanks for the help.


1 Comment

This forum was closed last year Nov 15.
The new forum at nextion.itead.cc opened Sep 2017.