Hi, i have an issue with my code : I am working on a buzzer that goes faster and faster and so i am using the formula : timeBetweenBeep = 100 + 900 * (timeLeft / InitialTime ) to get the time between each beeps but my issue is that it always give me 100 when i execute it instead of a number between 1 and 0
Here is the code :
int timeBetweenBeep = 0;
int timeByBeep = 125;
void setup() {
Serial.begin(9600);
}
void loop() {
int timeLeft = 40000 - millis();
if(timeLeft > 0){
Serial.println(timeLeft);
delay(100);
int timeBetweenBeep = 100 + 900 * (timeLeft / 40000);
Serial.println(timeBetweenBeep);
}
}
if you only have 100, either timeLeft or InitialTime are zero... or if InitialTime is very large compared to timeLeft that will bring 900 close to zero.