URS - LV11 - HMI - 2. zadatak

Dependencies:   mbed

Committer:
dfraj
Date:
Fri Jan 21 10:48:16 2022 +0000
Revision:
0:57ec9c61562e
Child:
1:a397ad7e537b
URS - LV11 - HMI - 2. zadatak

Who changed what in which revision?

UserRevisionLine numberNew 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 t.start();
dfraj 0:57ec9c61562e 16 flag = true;
dfraj 0:57ec9c61562e 17 }
dfraj 0:57ec9c61562e 18
dfraj 0:57ec9c61562e 19 void data(){
dfraj 0:57ec9c61562e 20 if (t.read() < 1.0 && flag)
dfraj 0:57ec9c61562e 21 rpm = 30.0/T; // rpm = 60 * f = 60 * 1/T * 1/2 = 30/T
dfraj 0:57ec9c61562e 22 else rpm = 0;
dfraj 0:57ec9c61562e 23 nextion.printf("t1.txt=\"%d rpm\"%c%c%c", rpm, 255, 255, 255);
dfraj 0:57ec9c61562e 24 nextion.printf("add 5,0,%d%c%c%c", rpm/100, 255, 255, 255);
dfraj 0:57ec9c61562e 25 }
dfraj 0:57ec9c61562e 26
dfraj 0:57ec9c61562e 27 int main(){
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 }