int buzzerPin = 7;
float start = 0;
bool once = true;
float total_time = 45.0;
void setup() {
pinMode(buzzerPin, OUTPUT);
start = millis();
Serial.begin(115200);
Serial.println("Bomb has been planted!");
}
float getBPS(float c_time, float exp_time)
{
float time = 45.0 * c_time / exp_time;
float n = (0.00000542275012008209 * time) + (0.000000000871011529375232 * time * time);
float bps = 1.04865094758501 * exp(n);
return bps;
}
void playFor(int freq, int duration)
{
tone(buzzerPin, freq);
delay(duration);
noTone(buzzerPin);
}
void loop() {
float time = (millis() - start);
if(time < total_time * 1000.0)
{
playFor(4000,125);
delay(1000.0/getBPS(time, total_time));
}
else
{
if(once){
Serial.println("\nBOOOM!");
for(int i = 1500; i <10750;i+=22 ) {
tone(buzzerPin,i);
delay(5);
}
for(int i = 0; i < 6;i+=1) {
playFor(3400,50);
delay(50);
playFor(3360,50);
delay(50);
}
once = false;
}
else
{
noTone(buzzerPin);
}
}
}