URS - LV11 - HMI - 2. zadatak
Dependencies: mbed
main.cpp@1:a397ad7e537b, 2022-01-22 (annotated)
- Committer:
- dfraj
- Date:
- Sat Jan 22 21:09:42 2022 +0000
- Revision:
- 1:a397ad7e537b
- Parent:
- 0:57ec9c61562e
- Child:
- 2:d7142743ba21
pokretanje tajmera premjesteno iz funkcije prolaz u glavnu funkciju
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dfraj | 0:57ec9c61562e | 1 | #include "mbed.h" |
dfraj | 0:57ec9c61562e | 2 | |
dfraj | 0:57ec9c61562e | 3 | InterruptIn optic(p18); |
dfraj | 0:57ec9c61562e | 4 | Serial nextion(p28, p27); |
dfraj | 0:57ec9c61562e | 5 | Ticker sendData; |
dfraj | 0:57ec9c61562e | 6 | |
dfraj | 0:57ec9c61562e | 7 | Timer t; |
dfraj | 0:57ec9c61562e | 8 | float T = 0; |
dfraj | 0:57ec9c61562e | 9 | uint16_t rpm = 0; |
dfraj | 0:57ec9c61562e | 10 | bool flag = false; |
dfraj | 0:57ec9c61562e | 11 | |
dfraj | 0:57ec9c61562e | 12 | void prolaz(){ |
dfraj | 0:57ec9c61562e | 13 | T = t.read(); |
dfraj | 0:57ec9c61562e | 14 | t.reset(); |
dfraj | 0:57ec9c61562e | 15 | flag = true; |
dfraj | 0:57ec9c61562e | 16 | } |
dfraj | 0:57ec9c61562e | 17 | |
dfraj | 0:57ec9c61562e | 18 | void data(){ |
dfraj | 0:57ec9c61562e | 19 | if (t.read() < 1.0 && flag) |
dfraj | 0:57ec9c61562e | 20 | rpm = 30.0/T; // rpm = 60 * f = 60 * 1/T * 1/2 = 30/T |
dfraj | 0:57ec9c61562e | 21 | else rpm = 0; |
dfraj | 0:57ec9c61562e | 22 | nextion.printf("t1.txt=\"%d rpm\"%c%c%c", rpm, 255, 255, 255); |
dfraj | 0:57ec9c61562e | 23 | nextion.printf("add 5,0,%d%c%c%c", rpm/100, 255, 255, 255); |
dfraj | 0:57ec9c61562e | 24 | } |
dfraj | 0:57ec9c61562e | 25 | |
dfraj | 0:57ec9c61562e | 26 | int main(){ |
dfraj | 1:a397ad7e537b | 27 | t.start(); |
dfraj | 0:57ec9c61562e | 28 | optic.rise(&prolaz); |
dfraj | 0:57ec9c61562e | 29 | sendData.attach(&data, 1.0); |
dfraj | 0:57ec9c61562e | 30 | while(1) { |
dfraj | 0:57ec9c61562e | 31 | wait(1.0); |
dfraj | 0:57ec9c61562e | 32 | } |
dfraj | 0:57ec9c61562e | 33 | } |