El-POM1001 / Mbed 2 deprecated LAB03_Oppgave2

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 InterruptIn SW7(PB_3);
00004 InterruptIn SW6(PA_10);
00005 
00006 Timer timer;
00007 
00008 void startKlokke();
00009 void stoppKlokke();
00010 void print();
00011 
00012 int main() 
00013 {    
00014     
00015     printf("Velkommen\n");
00016 
00017     SW7.fall(&startKlokke);
00018     SW6.fall(&stoppKlokke);
00019 
00020     while(1) 
00021     {
00022         
00023     }
00024     
00025 }
00026 void startKlokke()
00027 {
00028    timer.reset();
00029    timer.start();        
00030 }
00031     
00032 void stoppKlokke()
00033 {
00034     timer.stop();
00035     print();   
00036 }
00037 
00038 void print()
00039 {
00040     float tidSek=timer.read();
00041     float hastighet = (5/tidSek)*3.6;
00042     
00043     printf("Hastighet %.2f Km\\t\r\n", hastighet); 
00044 }