witches »
Â
HW-20: Arduino - Motor Speed.problem
Arduino - Measuring Motor Speed
Arduino sketch with corresponding line numbers percoding line.
Match line # 1 through #17 with the corresponding instructionpurpose.
_____________________________________________________________________
1.  int count = 0;
    float f = 0;
    float PPR = 500;
    float RPM= 0;
2.  void setup()
3.     pinMode(2,INPUT);
4.     attachInterrupt(0,freq,RISING);
5.     Serial.begin(9600);
6.   void loop()
     {
7.     count=0;
8.     delay(100);
9.     f=10*count;
10.   RPM=f/PPR;
11.   Serial.print(count);
12.   Serial.print(\" Pulses/100ms\");
13.   Serial.print(\"\t\");
14.   Serial.print(f);
15.   Serial.println(\" Hz\");
      }
16.  void freq()
       {Â
17.     count=count++;Â
       }
 1 2 3 4 5  Establish inputs andoutputsÂ
 1 2 3 4 5  DeclareVariablesÂ
 1 2 3 4 5  Establish outputcommunications with the monitorÂ
 1 2 3 4 5  Declare digitalinput pinÂ
 1 2 3 4 5  Establish interruptdigital input pin, name and modeÂ
 Tries 0/2
 6 7 8 9 10  Establish initialcount value within the running program loopÂ
 6 7 8 9 10  Infinite loop -running programÂ
 6 7 8 9 10  Calculaterevolutions per minuteÂ
 6 7 8 9 10  CalculatefreqencyÂ
 6 7 8 9 10  Delay 100 ms whilecounting interrupt pulsesÂ
 Tries 0/2
 11 12 13 14 15  Print text\"Pulses/100ms\" to monitorÂ
 11 12 13 14 15  Print countvalue to monitorÂ
 11 12 13 14 15  Print text \"Hz\" to monitor then line feedÂ
 11 12 13 14 15  Print frequencyvalue to monitorÂ
 11 12 13 14 15  Print tabspacing to monitorÂ
 Tries 0/2
 16 17  Interrupt subroutineÂ
 16 17  Add one to the count which isaccumulating the number of pulses in 100msÂ
 Tries 0/2