Advertisement
iurisantana

Untitled

Jul 25th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include <Stepper.h>
  2. #define STEPS 32 // 40 - 60 Steps for Opel Tacho
  3. #define SPEED 7000 // Speed in Rounds per Minute
  4. Stepper stepperSPEED(STEPS, 8, 10, 9, 11);
  5. int valSPEED = 0;
  6. int previousSPEED = 0;
  7. int pwm=9;
  8. int pot=A0;
  9. float value=0;
  10. int percent;
  11. float rev=0;
  12. int rpm;
  13. int oldtime=0;
  14. int time;
  15. void isr() //interrupt service routine
  16. {
  17. rev++;
  18. }
  19. void setup()
  20. {
  21. Serial.begin(9600);
  22. stepperSPEED.setSpeed(60);
  23. }
  24. void loop()
  25. {
  26. delay(150);
  27. detachInterrupt(0); //detaches the interrupt
  28. time=millis()-oldtime; //finds the time
  29. rpm=(rev/time)*60000; //calculates rpm
  30. oldtime=millis(); //saves the current time
  31. rev=0;
  32. value=analogRead(pot); //reads the speed control POT
  33. value=value/2;
  34. analogWrite(pwm,value); //sets the desired speed
  35. percent=(value/255)*100; //finds the duty cycle %
  36. attachInterrupt(0,isr,RISING);
  37. valSPEED = rpm/333;
  38. Serial.println(valSPEED-previousSPEED);
  39. stepperSPEED.step(-((valSPEED - previousSPEED)/10));
  40. previousSPEED = valSPEED;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement