Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
main.cpp@0:66e658666f89, 2022-01-15 (annotated)
- Committer:
- dfraj
- Date:
- Sat Jan 15 08:49:39 2022 +0000
- Revision:
- 0:66e658666f89
- Child:
- 1:53649f3053fc
Nextion - HMI - 1. zadatak
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dfraj | 0:66e658666f89 | 1 | #include "mbed.h" |
dfraj | 0:66e658666f89 | 2 | |
dfraj | 0:66e658666f89 | 3 | Serial nextion(p28, p27); |
dfraj | 0:66e658666f89 | 4 | DigitalOut myled1(LED2); |
dfraj | 0:66e658666f89 | 5 | DigitalOut myled2(LED4); |
dfraj | 0:66e658666f89 | 6 | |
dfraj | 0:66e658666f89 | 7 | char buffer[20]; |
dfraj | 0:66e658666f89 | 8 | int znak = 0; |
dfraj | 0:66e658666f89 | 9 | |
dfraj | 0:66e658666f89 | 10 | void Rx_interrupt(void){ |
dfraj | 0:66e658666f89 | 11 | char c; |
dfraj | 0:66e658666f89 | 12 | if(nextion.readable()) { |
dfraj | 0:66e658666f89 | 13 | c = nextion.getc(); |
dfraj | 0:66e658666f89 | 14 | buffer[znak] = c; |
dfraj | 0:66e658666f89 | 15 | znak++; |
dfraj | 0:66e658666f89 | 16 | if ((znak >= 3) && (buffer[znak-1] == 0xff) && (buffer[znak-2] == 0xff) && (buffer[znak-3] == 0xff)) { |
dfraj | 0:66e658666f89 | 17 | nextion.printf("\n\r"); |
dfraj | 0:66e658666f89 | 18 | if (buffer[2] == 0x04){ |
dfraj | 0:66e658666f89 | 19 | myled1 = buffer[3]; |
dfraj | 0:66e658666f89 | 20 | }else if (buffer[0] == 0x5A){ |
dfraj | 0:66e658666f89 | 21 | myled2 = buffer[1] - 48; |
dfraj | 0:66e658666f89 | 22 | } |
dfraj | 0:66e658666f89 | 23 | memset(buffer,0,strlen(buffer)); |
dfraj | 0:66e658666f89 | 24 | znak = 0; |
dfraj | 0:66e658666f89 | 25 | } |
dfraj | 0:66e658666f89 | 26 | } |
dfraj | 0:66e658666f89 | 27 | } |
dfraj | 0:66e658666f89 | 28 | |
dfraj | 0:66e658666f89 | 29 | int main(){ |
dfraj | 0:66e658666f89 | 30 | nextion.attach(&Rx_interrupt, Serial::RxIrq); |
dfraj | 0:66e658666f89 | 31 | while (1) { |
dfraj | 0:66e658666f89 | 32 | } |
dfraj | 0:66e658666f89 | 33 | } |