Hello,
If I run the void loop as just continues loop, it works. However if I run it as the following, it stops responding. Please help!
volatile int NbTopsFan; //measuring the rising edges of the signal
int Calc;
int inByte = 0;
const int FlowMeter_PIN2 = 2; //-- Flow Meter Pin
//const int FlowMeter_PIN3 = 3; //-- Flow Meter Pin
void setup(){
// start serial port to show results
Serial.begin(9600);
//initializes digital pin 2&3 as an input
pinMode(FlowMeter_PIN2, INPUT);
// pinMode(FlowMeter_PIN3, INPUT);
// Initialize the flow meter: pin 2&3 and set the Interrupt
attachInterrupt(0, rpm, RISING);
// attachInterrupt(1, rpm, RISING);
}// End setup
void loop(){
if (Serial.available() > 0) {
inByte = Serial.read();
switch(inByte){
case 'A':
NbTopsFan = 0; //Set NbTops to 0 ready for calculations
sei(); //Enables interrupts
delay (1000); //Wait 1 second
cli(); //Disable interrupts
Calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate in L/hour
Serial.print (Calc, DEC); //Prints the number calculated above
Serial.print (" L/minute \r\n"); //Prints "L/minute " and returns a new line
break;
}// End Switch
}// Endif serial aviable
}// End Main Loop
//This is the function that the interupt calls
void rpm (){
NbTopsFan++; //This function measures the rising and falling edge of the hall effect sensors signal
}