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@1:a59853df510d, 2022-01-24 (annotated)
- Committer:
 - dfraj
 - Date:
 - Mon Jan 24 09:13:29 2022 +0000
 - Revision:
 - 1:a59853df510d
 - Parent:
 - 0:0bb9abf8a951
 - Child:
 - 2:71767bf8e14d
 
izmjena logike provjere podatka
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| dfraj | 1:a59853df510d | 1 | #include "mbed.h" | 
| dfraj | 1:a59853df510d | 2 | |
| dfraj | 0:0bb9abf8a951 | 3 | Serial nextion(p28, p27); | 
| dfraj | 0:0bb9abf8a951 | 4 | PwmOut servo(p21); | 
| dfraj | 1:a59853df510d | 5 | |
| dfraj | 0:0bb9abf8a951 | 6 | char buffer[20]; | 
| dfraj | 0:0bb9abf8a951 | 7 | int znak = 0; | 
| dfraj | 1:a59853df510d | 8 | |
| dfraj | 0:0bb9abf8a951 | 9 | uint8_t pozicija = 0; | 
| dfraj | 1:a59853df510d | 10 | |
| dfraj | 0:0bb9abf8a951 | 11 | void Rx_interrupt(void){ | 
| dfraj | 0:0bb9abf8a951 | 12 | char c; | 
| dfraj | 1:a59853df510d | 13 | |
| dfraj | 0:0bb9abf8a951 | 14 | if(nextion.readable()) { | 
| dfraj | 0:0bb9abf8a951 | 15 | c = nextion.getc(); | 
| dfraj | 0:0bb9abf8a951 | 16 | buffer[znak] = c; | 
| dfraj | 0:0bb9abf8a951 | 17 | znak++; | 
| dfraj | 1:a59853df510d | 18 | |
| dfraj | 1:a59853df510d | 19 | if ((znak >= 2) && (buffer[znak-1] == 0x0d)) { | 
| dfraj | 0:0bb9abf8a951 | 20 | pozicija = 0; | 
| dfraj | 0:0bb9abf8a951 | 21 | for(int i = 0; i < 3; i++) { | 
| dfraj | 1:a59853df510d | 22 | if(buffer[i] == 0x0d) break; | 
| dfraj | 0:0bb9abf8a951 | 23 | pozicija = pozicija * 10 + (buffer[i] - 48); | 
| dfraj | 0:0bb9abf8a951 | 24 | } | 
| dfraj | 0:0bb9abf8a951 | 25 | servo.pulsewidth_us(5.56*pozicija+1000); | 
| dfraj | 0:0bb9abf8a951 | 26 | memset(buffer,0,strlen(buffer)); | 
| dfraj | 0:0bb9abf8a951 | 27 | znak = 0; | 
| dfraj | 0:0bb9abf8a951 | 28 | } | 
| dfraj | 0:0bb9abf8a951 | 29 | } | 
| dfraj | 0:0bb9abf8a951 | 30 | } | 
| dfraj | 1:a59853df510d | 31 | |
| dfraj | 0:0bb9abf8a951 | 32 | int main(){ | 
| dfraj | 0:0bb9abf8a951 | 33 | nextion .attach(&Rx_interrupt, Serial::RxIrq); | 
| dfraj | 0:0bb9abf8a951 | 34 | servo.period(0.02); | 
| dfraj | 0:0bb9abf8a951 | 35 | while (1) { | 
| dfraj | 0:0bb9abf8a951 | 36 | wait(1.0); | 
| dfraj | 0:0bb9abf8a951 | 37 | } | 
| dfraj | 0:0bb9abf8a951 | 38 | } |