Nextion - HMI - 1. zadatak
Dependencies: mbed
main.cpp
00001 #include "mbed.h" 00002 00003 Serial nextion(p28, p27); 00004 DigitalOut myled1(LED2); 00005 DigitalOut myled2(LED4); 00006 00007 char buffer[20]; 00008 int znak = 0; 00009 00010 void Rx_interrupt(void){ 00011 char c; 00012 if(nextion.readable()) { 00013 c = nextion.getc(); 00014 buffer[znak] = c; 00015 znak++; 00016 if ((znak >= 3) && (buffer[znak-1] == 0xff) && (buffer[znak-2] == 0xff) && (buffer[znak-3] == 0xff)) { 00017 if (buffer[0] == 0x43){ 00018 myled1 = !myled1; 00019 }else if (buffer[0] == 0x5A){ 00020 myled2 = buffer[1] - 48; 00021 } 00022 memset(buffer,0,strlen(buffer)); 00023 znak = 0; 00024 } 00025 } 00026 } 00027 00028 int main(){ 00029 nextion.attach(&Rx_interrupt, Serial::RxIrq); 00030 while (1) { 00031 } 00032 }
Generated on Tue Jul 12 2022 14:30:37 by 1.7.2