Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- volatile byte rpmcount;
- unsigned int rpm;
- unsigned long timeold;
- void setup()
- {
- Serial.begin(9600);
- attachInterrupt(A5, rpm_fun, RISING);
- rpmcount = 0;
- rpm = 0;
- timeold = 0;
- }
- void loop()
- {
- if (rpmcount >= 2) {
- //Update RPM every 20 counts, increase this for better RPM resolution,
- //decrease for faster update
- rpm = 30*1000/(millis() - timeold)*rpmcount;
- timeold = millis();
- rpmcount = 0;
- Serial.println(rpm);
- rpm=0;
- delay(100);
- }
- }
- void rpm_fun()
- {
- rpmcount++;
- //Each rotation, this interrupt function is run twice
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement