BRLAB DOCS
HomeTutorialsHardware
Control Relays with the Nextion HMI and Arduino
Control Relays with the Nextion HMI and Arduino
  • Introduction
  • GETTING STARTED
    • What You Will Need
    • Wiring
  • HMI GUI
    • Nextion HMI Setup
    • GUI Design
    • HMI Code
    • Load Code on the HMI
  • NANO EVERY CODE
    • Task to Complete
    • Writing the Code
      • Comment Header
      • Define Global Variables
      • void setup()
      • void loop()
      • void serial_input()
    • Application Code
    • Files
Powered by GitBook
On this page
  1. NANO EVERY CODE
  2. Writing the Code

void loop()

The void loop() is the loop that runs contiously. I also want to keep this section of the code clean and simple. To do that I am just going to see if there is any data on the serial port to be read. If so then I am going to clear out the cmd string, delay for 5ms just to ensure all the data is across, and then run a custom function called serial_input() to proccess the data.

void loop() {
  if(Serial1.available()){ // is there any bytes on the serial 1 port buffer
    cmd = "";
    delay(5);
    serial_input(); // custom function to handle the messages over serial 
  }
}
Previousvoid setup()Nextvoid serial_input()

Last updated 2 years ago