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.
main.cpp
00001 #include "mbed.h" 00002 00003 #define TICKS_PER_REVOLUTION 12.0 00004 #define TICK_CHECK_PERIOD 0.1 00005 00006 DigitalOut myled(LED1); 00007 Serial pc(USBTX, USBRX); // tx, rx 00008 Ticker periodicTimer1, periodicTimer2; 00009 00010 float speed_rpm, speed_rps, ticks_per_second; 00011 volatile unsigned int tick_counter, final_count; 00012 00013 InterruptIn freqInputPin(D2); 00014 00015 void freqInputPin_Interrupt() { 00016 //Triggers on the rising edge of the frequency signal 00017 tick_counter++; 00018 } 00019 00020 void check_TickCount(){ 00021 final_count = tick_counter; 00022 //pc.printf("\n\rTick Count is : %d", final_count); 00023 tick_counter = 0; 00024 } 00025 00026 void display_TickCount(){ 00027 //pc.printf("\n\r Final Count is : %.2f", (float) final_count*(1.0/TICK_CHECK_PERIOD)); 00028 pc.printf("\n\r Speed in RPM is : %.2f", (float)(final_count*(1.0/TICK_CHECK_PERIOD))*(60.0/TICKS_PER_REVOLUTION)); 00029 } 00030 00031 int main() { 00032 freqInputPin.rise(&freqInputPin_Interrupt); //chain interrupt to rising edge 00033 periodicTimer1.attach(&check_TickCount, TICK_CHECK_PERIOD); 00034 periodicTimer2.attach(&display_TickCount, 1.0); //Display conut once a second 00035 while(1) { 00036 } 00037 }
Generated on Thu Jul 28 2022 04:09:27 by
1.7.2