// Pin for the speaker
const int speakerPin = 3;

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

void setup() {
  // Initialize speaker pin as output
  pinMode(speakerPin, OUTPUT);

  // Initialize serial communication
  Serial.begin(9600);  // Start serial communication at 9600 baud rate
}

void loop() {
  // Frequency for the tone (440 Hz is the note A4)
  int frequency = 440;

  // Loop through the Fibonacci intervals and play sound
  for (int i = 0; i < 8; i++) {
    int interval = intervals[i];

    // Print the current Fibonacci interval to the serial monitor
    Serial.print("Playing tone for ");
    Serial.print(interval / 1000.0);  // Convert to seconds for readability
    Serial.println(" seconds...");

    // Play the tone on the speaker for the current interval
    tone(speakerPin, frequency, 500);  // 500ms tone duration

    // Wait for the Fibonacci interval before the next tone
    delay(interval);

    // Stop the tone
    noTone(speakerPin);

    // Delay before the next sound
    delay(100); // A small delay between tones
  }

  // Optionally, loop or stop after a single cycle
  while (true);  // Stops the loop, remove this line if you want the loop to repeat
}