#define Btn1_GPIO 4
int counter;
int speed;
const long interval = 1000;
unsigned long previousMillis = 0;
void setup()
{
pinMode(Btn1_GPIO, INPUT);
attachInterrupt(Btn1_GPIO, SW_DETECT, RISING);
Serial.begin(9600);
}
void loop()
{
unsigned long currentMillis = millis();
//to calculate speed
if(currentMillis = previousMillis >= interval) {
previousMillis = currentMillis;
speed=counter/10;
counter=0;
}
Serial.println(counter);
Serial.println(speed);
delay(500);
}
//interrupt call function
void SW_DETECT()
{
counter++;
}