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