Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Stepper.h>
- #define STEPS 32 // 40 - 60 Steps for Opel Tacho
- #define SPEED 7000 // Speed in Rounds per Minute
- Stepper stepperSPEED(STEPS, 8, 10, 9, 11);
- int valSPEED = 0;
- int previousSPEED = 0;
- int pwm=9;
- int pot=A0;
- float value=0;
- int percent;
- float rev=0;
- int rpm;
- int oldtime=0;
- int time;
- void isr() //interrupt service routine
- {
- rev++;
- }
- void setup()
- {
- Serial.begin(9600);
- stepperSPEED.setSpeed(60);
- }
- void loop()
- {
- delay(150);
- detachInterrupt(0); //detaches the interrupt
- time=millis()-oldtime; //finds the time
- rpm=(rev/time)*60000; //calculates rpm
- oldtime=millis(); //saves the current time
- rev=0;
- value=analogRead(pot); //reads the speed control POT
- value=value/2;
- analogWrite(pwm,value); //sets the desired speed
- percent=(value/255)*100; //finds the duty cycle %
- attachInterrupt(0,isr,RISING);
- valSPEED = rpm/333;
- Serial.println(valSPEED-previousSPEED);
- stepperSPEED.step(-((valSPEED - previousSPEED)/10));
- previousSPEED = valSPEED;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement