Devices & Components
Arduino UNO EK (एक) R4 WiFi
USB Cable, USB Type C Plug
mini-breadboard ROBU
Robu Jumper wires
SmartElex 3.5 inch HMI Display
Software & Tools
Arduino IDE
Robu's HMI Editor
Project description
Code
Touch-to-Light: Control LEDs with Arduino and HMI Display
cpp
Interface the display in Robu's HMI editor
1char buffer[40]; 2int idx = 0; 3 4const int redLED = 9; 5const int yellowLED = 8; 6const int greenLED = 7; 7 8void setup() { 9 Serial.begin(115200); 10 Serial1.begin(115200); 11 12 pinMode(redLED, OUTPUT); 13 pinMode(yellowLED, OUTPUT); 14 pinMode(greenLED, OUTPUT); 15 16 // Start all OFF 17 digitalWrite(redLED, LOW); 18 digitalWrite(yellowLED, LOW); 19 digitalWrite(greenLED, LOW); 20 21 Serial.println("System Ready..."); 22} 23 24void loop() { 25 while (Serial1.available()) { 26 char c = Serial1.read(); 27 28 if (idx < sizeof(buffer) - 1) { 29 buffer[idx++] = c; 30 } 31 32 if (c == '\n' || c == '\r') { // End of packet 33 buffer[idx] = '\0'; 34 if (idx > 0) { 35 parsePacket(buffer); 36 } 37 idx = 0; // Reset for next packet 38 } 39 } 40} 41 42void parsePacket(char *pkt) { 43 Serial.print("RX: "); 44 Serial.println(pkt); 45 46 int page = 0, type = 0, id = 0, value = -1; 47 48 if (sscanf(pkt, "P%dT%dI%dV%d", &page, &type, &id, &value) == 4) { 49 if (value == 1) { // Only act on press 50 if (page == 5 && type == 11 && id == 0) { 51 // Red 52 digitalWrite(redLED, HIGH); 53 digitalWrite(yellowLED, LOW); 54 digitalWrite(greenLED, LOW); 55 Serial.println("Red LED -> ON"); 56 } 57 else if (page == 5 && type == 11 && id == 1) { 58 // Yellow 59 digitalWrite(redLED, LOW); 60 digitalWrite(yellowLED, HIGH); 61 digitalWrite(greenLED, LOW); 62 Serial.println("Yellow LED -> ON"); 63 } 64 else if (page == 6 && type == 11 && id == 0) { 65 // Green 66 digitalWrite(redLED, LOW); 67 digitalWrite(yellowLED, LOW); 68 digitalWrite(greenLED, HIGH); 69 Serial.println("Green LED -> ON"); 70 } 71 } 72 // Ignore V=0 (release) 73 } 74}
Downloadable files
Control LEDs with Arduino and HMI Display
install Robu's HMI editor
CKT HMI Display.jpg

Documentation
Robu's HMI Editor Guide
follow this guide to create HMI display
Robus-HMI-Display-Editor-Guide.pdf
Comments
Only logged in users can leave comments