const int speakerPin = 3;

// Fibonacci intervals (in milliseconds)
int intervals[] = { 21000, 13000, 8000, 5000, 3000, 2000, 1000, 1000};

void setup() {
  pinMode(speakerPin, OUTPUT); // Set the speaker pin as an output
  Serial.begin(9600); // Initialize serial communication at a baud rate of 9600
}

void loop() {
  for (int i = 0; i < 24; i++) { // Loop through the heartbeat intervals
    int interval = intervals[i]; // Get the current interval

    Serial.print("Playing heartbeat for ");
    Serial.print(interval / 1000.0); // Convert interval to seconds for readability
    Serial.println(" seconds...");

    // Simulate the "lub" sound of the heartbeat
    tone(speakerPin, 150, 100); // Play a 150Hz tone for 100 milliseconds
    delay(200); // Short pause between "lub" and "dub"

    // Simulate the "dub" sound of the heartbeat
    tone(speakerPin, 150, 100); // Play a 150Hz tone for 100 milliseconds
    delay(interval - 300); // Wait for the rest of the interval

    noTone(speakerPin); // Stop the tone
    delay(100); // Small delay between beats
  }

  while (true); // Stop the loop (remove this line to repeat the loop)
}