Product Preview: Nextion in an Arduino project (3)

In the previous blog, we demonstrate how to use Arduino to control a progress bar that shows on Nextion 2.4”. In that case, we use progress bar and text components in Nextion Editor. In this blog, we will tell you the other simple component – button. When you touch the area that is under the button component “monitor”, it will run the ID of this component, then you can realize some visual final effects like interface switching, sending data through serial port.

Hardware we use

  • Iteaduino UNO
  • Nextion 2.4″

Download the HMI file here: Touch_switch_Project

IFrame

未知对象

Code we use to Arduino UNO:

int char1,char2;
int charflag=0;

void setup() {
  Serial.begin(9600);
  pinMode(13,OUTPUT);
}

void loop() {
 if (Serial.available()>1) 
{
 if (charflag)  
  {
  char2=Serial.read();
  if (char2==0) digitalWrite(13,HIGH);
  else if (char2==0x01) digitalWrite(13,LOW);
  charflag=0;
  }
  else
  {
   char1=Serial.read();
   if(char1==0x65) charflag=1;
  }
}
}
%d bloggers like this: