#include <Arduino.h> // Explicitly include the standard Arduino header file
// Pin definitions
static const int LED = 2; // LED connected to digital pin 2
static const int BUZZER = 3; // Buzzer connected to digital pin 3
// Time delays (in milliseconds)
static const unsigned int LED_ON_TIME = 5000U; // LED stays ON for 5 seconds
static const unsigned int BUZZER_BEEP_DELAY = 300U; // Buzzer beep duration
void setup(void)
{
pinMode(LED, OUTPUT); // Set LED pin as an output
pinMode(BUZZER, OUTPUT); // Set Buzzer pin as an output
}
void beepBuzzer(void)
{
for (int i = 0; i < 3; i++) // Loop to beep the buzzer 3 times
{
digitalWrite(BUZZER, HIGH); // Turn buzzer ON
delay(BUZZER_BEEP_DELAY); // Wait for beep duration
digitalWrite(BUZZER, LOW); // Turn buzzer OFF
delay(BUZZER_BEEP_DELAY); // Wait before next beep
}
}
void loop(void)
{
digitalWrite(LED, HIGH); // Turn on LED
beepBuzzer(); // Call function to beep buzzer 3 times
delay(LED_ON_TIME); // Keep LED on for 5 seconds
digitalWrite(LED, LOW); // Turn off LED
delay(2000); // Wait for 2 seconds before repeating
}