URS - LV11 - HMI - 2. zadatak
Dependencies: mbed
main.cpp
00001 #include "mbed.h" 00002 00003 InterruptIn optic(p18); 00004 Serial nextion(p28, p27); 00005 Ticker sendData; 00006 00007 Timer t; 00008 float T = 0; 00009 uint16_t rpm = 0; 00010 bool flag = false; 00011 00012 void prolaz(){ 00013 T = t.read(); 00014 t.reset(); 00015 flag = true; 00016 } 00017 00018 void data(){ 00019 if (t.read() < 1.0 && flag) 00020 rpm = 30.0/T; // rpm = 60 * f = 60 * 1/T * 1/2 = 30/T 00021 else rpm = 0; 00022 nextion.printf("t1.txt=\"%d rpm\"%c%c%c", rpm, 255, 255, 255); //t1.txt="tekst" 0xFF 0xFF 0xFF 00023 nextion.printf("add 5,0,%d%c%c%c", rpm/100, 255, 255, 255); //add <waveform>,<channel>,<value> 0xFF 0xFF 0xFF 00024 } 00025 00026 int main(){ 00027 t.start(); 00028 optic.rise(&prolaz); 00029 sendData.attach(&data, 1.0); 00030 while(1) { 00031 wait(1.0); 00032 } 00033 }
Generated on Tue Jul 12 2022 14:30:38 by 1.7.2