Nextion - HMI - 1. zadatak
Dependencies: mbed
main.cpp
- Committer:
- dfraj
- Date:
- 2022-01-24
- Revision:
- 4:11d61285b2f0
- Parent:
- 3:83cf2072b25d
File content as of revision 4:11d61285b2f0:
#include "mbed.h" Serial nextion(p28, p27); DigitalOut myled1(LED2); DigitalOut myled2(LED4); char buffer[20]; int znak = 0; void Rx_interrupt(void){ char c; if(nextion.readable()) { c = nextion.getc(); buffer[znak] = c; znak++; if ((znak >= 3) && (buffer[znak-1] == 0xff) && (buffer[znak-2] == 0xff) && (buffer[znak-3] == 0xff)) { if (buffer[0] == 0x43){ myled1 = !myled1; }else if (buffer[0] == 0x5A){ myled2 = buffer[1] - 48; } memset(buffer,0,strlen(buffer)); znak = 0; } } } int main(){ nextion.attach(&Rx_interrupt, Serial::RxIrq); while (1) { } }