Thanks folks, here is the fully and updated code - currently it is reporting about 250 pulses each time with the anemometer staionary - I guess the IF loop is firing the false interrupts?
#include <PinChangeInt.h>
#define PIN1 7
volatile float WindSpeed = 0;
volatile int wPulse=0;
unsigned long currentTime;
unsigned long loopTime;
void setup()
{
Serial.begin(9600);
Serial.println("Starting...");
pinMode(PIN1, INPUT);
digitalWrite(PIN1, HIGH);
delay(1000);
}
void loop()
{
reportAnemometer();
delay(5000);
}
void reportAnemometer()
{
currentTime = millis();
loopTime=(currentTime+5000);
if(currentTime <= loopTime)
{attachInterrupt(PIN1, &windPulse, RISING);
}
else
{detachInterrupt(PIN1);
loopTime=0;}
WindSpeed = (wPulse/ 5) * 2.4; //2.4 K/h for one switch closure per second
Serial.print("wPulse: ");
Serial.println(wPulse);
Serial.print("WindSpeed: ");
Serial.println(WindSpeed);
wPulse=0;
WindSpeed=0;
}
void windPulse()
{
wPulse ++;
}