RPM tachometer + total counter

I already have working RPM meter for car. I would like to count total counts of shaft rotation also, and if is possible to save to EEPROM for example every 5 minutes. And when alduino restarts, I want to start counting from last saved number.

Thanks in advance!

/*  7.5 dodan array za temperaturo
 *  7.4 spremenjen map za temperaturo na -13 prej -20
 *  7.3 dodan beep pri inicializaciji oz. pri welcome screenu
 *  
 *  proba z digital inputom na pin 12 za ventilator 
 */

 // ver 7.5 arrayi
volatile float time = 0;
volatile float time_last = 0;
volatile int rpm_array[5] = {0,0,0,0,0};
 
volatile byte rpmcount;
unsigned int rpm;
unsigned long timeold;

// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
//LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
//LiquidCrystal lcd(10, 9, 5, 4, 3, 2);
LiquidCrystal lcd(10, 9, 7, 6, 5, 4);

void rpm_fun()
 {
   time = (micros() - time_last); 
   time_last = micros();
 }

void setup()
 {
    Serial.begin(9600);
    lcd.begin(16, 4);  // intialise the LCD

   //Interrupt 0 is digital pin 2, so that is where the IR detector is connected
   //Triggers on FALLING (change from HIGH to LOW)
   attachInterrupt(0, rpm_fun, RISING);

   rpmcount = 0;
   rpm = 0;
   timeold = 0;
 }

 void loop(){


   detachInterrupt(0);
   //dodano za array 7.5
   //5 Sample Moving Average To Smooth Out The Data
      rpm_array[0] = rpm_array[1];
      rpm_array[1] = rpm_array[2];
      rpm_array[2] = rpm_array[3];
      rpm_array[3] = rpm_array[4];
      rpm_array[4] = 60*(1000000/(time*1));    
    //Last 5 Average RPM Counts Eqauls....
      rpm = (rpm_array[0] + rpm_array[1] + rpm_array[2] + rpm_array[3] + rpm_array[4]) / 5;
      timeold = millis();
      rpmcount = 0;

   lcd.setCursor(0, 0);
   
   lcd.print(rpm);   
   lcd.print("  Obrati m.:");
   

 // lcd.setCursor(0, 1);
 // percent = map(rpm, 0, 3500, 0, 100);

 

   //Restart the interrupt processing
   attachInterrupt(0, rpm_fun, RISING);
  }

Use the blink without delay timing method to call a function to save to EEPROM every 5 minutes.

Thanks for the tip :slight_smile: