Advertisement
safwan092

Untitled

May 18th, 2022
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #include <LiquidCrystal_I2C.h>
  2. LiquidCrystal_I2C lcd(0x27, 16, 2);
  3.  
  4. float value = 0;
  5. float rev = 0;
  6. int rpm;
  7. int oldtime = 0;
  8. int time;
  9.  
  10. void isr()
  11. {
  12. rev++;
  13. }
  14.  
  15. void setup()
  16. {
  17. lcd.init();
  18. lcd.init();
  19. lcd.backlight();
  20. attachInterrupt(0, isr, RISING);
  21. }
  22.  
  23. void loop()
  24. {
  25. delay(1000);
  26. detachInterrupt(0);
  27. time = millis() - oldtime;
  28. rpm = (rev / time) * 60000;
  29. oldtime = millis();
  30. rev = 0;
  31. lcd.clear();
  32. lcd.setCursor(0, 0);
  33. lcd.print(" Tachometer ");
  34. lcd.setCursor(0, 1);
  35. lcd.print("RPM: ");
  36. lcd.setCursor(5, 1);
  37. lcd.print(rpm);
  38. lcd.print(" ");
  39. attachInterrupt(0, isr, RISING);
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement