int runtime = 0;
int Ptime = 0;
int PSenRead = 1;
int CSenRead = 0;
int count = 0;
const int range = 1000;
const int RPtime = 1000;
int RPS = 0;
int sensor;
void setup() {
// put your setup code here, to run once:
pinMode(A0, INPUT);
Serial.begin(11500);
}
void loop() {
runtime = millis();
sensor = digitalRead(A0);
// Serial.println(runtime);
if(PSenRead != sensor)
{
CSenRead = sensor ;
if (CSenRead ==0)
{
count++;
}
PSenRead = CSenRead;
}
// Serial.print(count);
// Serial.println(digitalRead(A0));
if(runtime-Ptime>range){
RPS = count;
Serial.print("RPS =");
Serial.println(RPS);
count = 0;
Ptime = runtime;
}
}