URS - LV11 - HMI - 2. zadatak
Dependencies: mbed
Diff: main.cpp
- Revision:
- 0:57ec9c61562e
- Child:
- 1:a397ad7e537b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Jan 21 10:48:16 2022 +0000 @@ -0,0 +1,33 @@ +#include "mbed.h" + +InterruptIn optic(p18); +Serial nextion(p28, p27); +Ticker sendData; + +Timer t; +float T = 0; +uint16_t rpm = 0; +bool flag = false; + +void prolaz(){ + T = t.read(); + t.reset(); + t.start(); + flag = true; +} + +void data(){ + if (t.read() < 1.0 && flag) + rpm = 30.0/T; // rpm = 60 * f = 60 * 1/T * 1/2 = 30/T + else rpm = 0; + nextion.printf("t1.txt=\"%d rpm\"%c%c%c", rpm, 255, 255, 255); + nextion.printf("add 5,0,%d%c%c%c", rpm/100, 255, 255, 255); +} + +int main(){ + optic.rise(&prolaz); + sendData.attach(&data, 1.0); + while(1) { + wait(1.0); + } +} \ No newline at end of file