Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. int pwm=9;
  2. int pot=A0;
  3. float value=0;
  4. int percent;
  5. float rev=0;
  6. int rpm;
  7. int oldtime=0;
  8. int time;
  9.  
  10. void isr() //interrupt service routine
  11. {
  12. rev++;
  13. }
  14.  
  15. void setup()
  16. {
  17. lcd.begin(16,2); //initialize LCD
  18. attachInterrupt(0,isr,RISING); //attaching the interrupt
  19. }
  20.  
  21. void loop()
  22. {
  23. delay(1000);
  24. detachInterrupt(0); //detaches the interrupt
  25. time=millis()-oldtime; //finds the time
  26. rpm=(rev/time)*60000; //calculates rpm
  27. oldtime=millis(); //saves the current time
  28. rev=0;
  29. value=50; // VALUES 0-255
  30. analogWrite(pwm,value); //sets the desired speed
  31. percent=(value/255)*100; //finds the duty cycle %
  32. lcd.clear();
  33. lcd.setCursor(1,0);
  34. lcd.print("__MOTOR___");
  35. lcd.setCursor(0,1);
  36. lcd.print(rpm);
  37. lcd.print(" RPM");
  38. lcd.print(" ");
  39. lcd.print(percent);
  40. lcd.print("%");
  41. lcd.print(" ");
  42. lcd.print("S.P");
  43. attachInterrupt(0,isr,RISING);
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement