HELP! programming Masters...
I have a project that reads RPM of a fan and I found a working program in the Net and used it with equivalent parts that I have.
The problem is, the rpm on the LCD doesn't reset or get back to zero whenever I'm not using the program..
What program should I add to reset its counter?
Please see below code that he used. Any help will be greatly appreciated. thanks in advance..
CODE:
#include <LiquidCrystal.h>
LiquidCrystal lcd(3, 5, 9, 10, 11, 12);
volatile float time = 0;
volatile float time_last = 0;
volatile int rpm_array[5] = {0,0,0,0,0};
void setup()
{
//Digital Pin 2 Set As An Interrupt
attachInterrupt(0, fan_interrupt, FALLING);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Current RPM:");
}
//Main Loop To Calculate RPM and Update LCD Display
void loop()
{
int rpm = 0;
while(1){
//Slow Down The LCD Display Updates
delay(400);
//Clear The Bottom Row
lcd.setCursor(0, 1);
lcd.print(" ");
//Update The Rpm Count
lcd.setCursor(0, 1);
lcd.print(rpm);
////lcd.setCursor(4, 1);
////lcd.print(time);
//Update The RPM
//if(time > 0)
//{
//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*2));
//Last 5 Average RPM Counts Eqauls....
rpm = (rpm_array[0] + rpm_array[1] + rpm_array[2] + rpm_array[3] + rpm_array[4]) / 5;
// }
}
}
//Capture The IR Break-Beam Interrupt
void fan_interrupt()
{
time = (micros() - time_last);
time_last = micros();
}