Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int ledPin = 13;
- volatile byte rpmcount;
- unsigned int rpm;
- unsigned long timeold;
- void rpm_fun() {
- rpmcount++;
- }
- void setup() {
- attachInterrupt(0, rpm_fun, FALLING);
- pinMode(ledPin, OUTPUT);
- digitalWrite(ledPin, HIGH);
- rpmcount = 0;
- rpm = 0;
- timeold = 0;
- }
- void loop() {
- delay(1000);
- detachInterrupt(0);
- rpm = 30*1000/(millis() - timeold)*rpmcount;
- timeold = millis();
- rpmcount = 0;
- attachInterrupt(0, rpm_fun, FALLING);
- }
Advertisement
Add Comment
Please, Sign In to add comment