Nextion - HMI - 1. zadatak
Dependencies: mbed
Revision 4:11d61285b2f0, committed 2022-01-24
- Comitter:
- dfraj
- Date:
- Mon Jan 24 09:12:02 2022 +0000
- Parent:
- 3:83cf2072b25d
- Commit message:
- ispravak greske
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 83cf2072b25d -r 11d61285b2f0 main.cpp --- a/main.cpp Mon Jan 24 09:05:33 2022 +0000 +++ b/main.cpp Mon Jan 24 09:12:02 2022 +0000 @@ -1,38 +1,32 @@ -#include "mbed.h" - -Serial nextion(p28, p27); -PwmOut servo(p21); +#include "mbed.h" -char buffer[20]; +Serial nextion(p28, p27); +DigitalOut myled1(LED2); +DigitalOut myled2(LED4); + +char buffer[20]; int znak = 0; -uint8_t pozicija = 0; - void Rx_interrupt(void){ char c; - if(nextion.readable()) { c = nextion.getc(); buffer[znak] = c; znak++; - - if ((znak >= 2) && (buffer[znak-1] == 0x0d)) { - pozicija = 0; - for(int i = 0; i < 3; i++) { - if(buffer[i] == 0x0d) break; - pozicija = pozicija * 10 + (buffer[i] - 48); + 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; } - servo.pulsewidth_us(5.56*pozicija+1000); - memset(buffer,0,strlen(buffer)); - znak = 0; + memset(buffer,0,strlen(buffer)); + znak = 0; } } -} +} int main(){ - nextion .attach(&Rx_interrupt, Serial::RxIrq); - servo.period(0.02); + nextion.attach(&Rx_interrupt, Serial::RxIrq); while (1) { - wait(1.0); } } \ No newline at end of file