tac

Dependencies:   mbed

Committer:
idied
Date:
Tue Nov 21 19:02:44 2017 +0000
Revision:
0:3ba0b3ceda17
tach

Who changed what in which revision?

UserRevisionLine numberNew contents of line
idied 0:3ba0b3ceda17 1 #include "mbed.h"
idied 0:3ba0b3ceda17 2
idied 0:3ba0b3ceda17 3 DigitalOut myled(LED1);
idied 0:3ba0b3ceda17 4
idied 0:3ba0b3ceda17 5 AnalogIn ain(A0); //initialize input
idied 0:3ba0b3ceda17 6 Timer t; //initialize timer
idied 0:3ba0b3ceda17 7 float rpm; //declare rpm variable
idied 0:3ba0b3ceda17 8
idied 0:3ba0b3ceda17 9 int main() {
idied 0:3ba0b3ceda17 10
idied 0:3ba0b3ceda17 11 while(1){ //do always
idied 0:3ba0b3ceda17 12 if (A0 != 0){ //senses beam crossing
idied 0:3ba0b3ceda17 13 while (A0 == 0) { //no longer senses
idied 0:3ba0b3ceda17 14 t.start(); //start timer
idied 0:3ba0b3ceda17 15 }
idied 0:3ba0b3ceda17 16 t.stop(); //stop timer
idied 0:3ba0b3ceda17 17 rpm = t.read()*60; //obtain value of rpm
idied 0:3ba0b3ceda17 18 }
idied 0:3ba0b3ceda17 19 }
idied 0:3ba0b3ceda17 20
idied 0:3ba0b3ceda17 21
idied 0:3ba0b3ceda17 22
idied 0:3ba0b3ceda17 23 }