I'm currently working on a project and i need to calculate time between to presses of a button and do some calculations on it and then show it on a display. currently I'm only printing it and it only prints inf and not a number. here is my code:
const int ledPin = 5;
const int btnPin = 33;
unsigned long start_time =1;
unsigned long time_passed;
double current_speed;
void setup() {
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
pinMode(btnPin, INPUT_PULLDOWN);
}
void loop() {
bool buttonState = digitalRead(btnPin);
if (buttonState==1){
time_passed = (millis() - start_time); //calculating time between to presses
if (time_passed > 25){ // checking if button is actually pressed and not hold
Serial.println(0.35/(time_passed/1000)*3.6); // this outputs "inf"
}
start_time = millis(); // resetting time
}
}