Advertisement
RuiViana

Calcula_RPM

Jan 25th, 2017
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. float numeroCil = 6;
  2. unsigned long tempoInicial;
  3. unsigned long pulsos;
  4. float rpm = 0;
  5. //-----------------------------------
  6. void ContaPulsos()
  7. {
  8.   pulsos++;
  9. }
  10. //------------------------------------
  11. void setup()
  12. {
  13.   Serial.begin(9600);
  14.   pulsos = 0;
  15.   attachInterrupt(0, ContaPulsos, RISING);
  16.   tempoInicial = millis();
  17. }
  18. //------------------------------------
  19. void loop()
  20. {
  21.   if ((millis() - tempoInicial) >= 200)
  22.   {
  23.     tempoInicial = millis();
  24.     rpm = (((float)pulsos / ((float)numeroCil / 2)) ) * 300;
  25.     Serial.println(rpm,0);
  26.     pulsos = 0;
  27.   }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement