Last active
May 5, 2018 00:47
-
-
Save LeonNardella/65b32a71f15893b61370d86cde77cd5c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const byte interruptPin = 2; | |
| volatile byte rpmcount; | |
| unsigned int rpm; | |
| unsigned long timeold; | |
| void rpm_fun() | |
| { | |
| rpmcount++; | |
| } | |
| void setup() | |
| { | |
| Serial.begin(9600); | |
| attachInterrupt(digitalPinToInterrupt(interruptPin), rpm_fun, FALLING); | |
| rpmcount = 0; | |
| rpm = 0; | |
| timeold = 0; | |
| } | |
| void loop() | |
| { | |
| delay(1000); | |
| detachInterrupt(0); | |
| rpm = 10 * 1000 / (millis() - timeold) * rpmcount; | |
| timeold = millis(); | |
| rpmcount = 0; | |
| Serial.println(rpm, DEC); | |
| attachInterrupt(digitalPinToInterrupt(interruptPin), rpm_fun, FALLING); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment