rosaage

Arduino rpm teller

Feb 27th, 2016
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.50 KB | None | 0 0
  1.  
  2. int ledPin = 13;
  3. volatile byte rpmcount;
  4. unsigned int rpm;
  5. unsigned long timeold;
  6.  
  7.  
  8. void rpm_fun() {
  9.    rpmcount++;
  10. }
  11.  
  12. void setup() {
  13.    attachInterrupt(0, rpm_fun, FALLING);
  14.  
  15.    pinMode(ledPin, OUTPUT);
  16.    digitalWrite(ledPin, HIGH);
  17.  
  18.    rpmcount = 0;
  19.    rpm = 0;
  20.    timeold = 0;
  21.  }
  22.  
  23.  void loop() {
  24.    delay(1000);
  25.    detachInterrupt(0);
  26.    rpm = 30*1000/(millis() - timeold)*rpmcount;
  27.    timeold = millis();
  28.    rpmcount = 0;
  29.  
  30.    
  31.  
  32.    attachInterrupt(0, rpm_fun, FALLING);
  33.  }
Advertisement
Add Comment
Please, Sign In to add comment