Advertisement
RuiViana

Contagiros

Jul 1st, 2016
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. volatile unsigned int pulsos = 0;
  2.  volatile unsigned long t;
  3. //-------------------------------
  4. void ContaPulso()
  5. {
  6.   pulsos++;
  7. }
  8. //-----------------------------
  9. void setup()
  10. {
  11.   Serial.begin(9600);
  12.   attachInterrupt(0, ContaPulso, RISING);
  13.   pinMode(2,INPUT_PULLUP);
  14.   t = millis();
  15. }
  16. void loop()
  17. //------------------------------
  18. {
  19.   if ((millis() - t) >= 1000)
  20.   {
  21.     int rpm = pulsos * 60;
  22.     Serial.print("RPM = ");
  23.     Serial.println(rpm);
  24.     t = millis();
  25.   }
  26.   pulsos = 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement