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
- #define Reed 2 // Port do reed switch
- Stepper stepperSPEED(STEPS, 8, 10, 9, 11);
- float rev = 0;
- int rpm;
- unsigned long Tempo;
- int diferenca = 0;
- int rpm_old = 0;
- //------------------------------
- void isr() //interrupt service routine
- {
- rev++;
- }
- //-------------------------------
- void setup()
- {
- pinMode(Reed, INPUT_PULLUP); // Define o port reeed como entrada e liga o pull up
- Serial.begin(9600);
- stepperSPEED.setSpeed(60);
- attachInterrupt(0, isr, RISING); // Interrupt do reed
- Tempo = millis();
- }
- //------------------------------
- void loop()
- {
- if (millis() - Tempo > 1000)
- {
- rpm = rev;
- Tempo = millis();
- rev = 0;
- // Serial.println(rpm);
- }
- diferenca = rpm - rpm_old;
- stepperSPEED.step(diferenca);
- rpm_old = rpm;
- // Serial.println(rpm);
- // Serial.println(rpm_old);
- if (diferenca != 0)
- Serial.println(diferenca);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement