#define BUZZER 2
#define BUTTON 12
#define LED_1 26
#define LED_2 25
#define CHN 0
void setup()
{
pinMode(BUZZER, OUTPUT);
pinMode(BUTTON, INPUT);
pinMode(LED_1, OUTPUT);
pinMode(LED_2, OUTPUT);
ledcSetup(CHN, 0, 10);
ledcAttachPin(BUZZER, CHN);
ledcWriteTone(CHN, 2000);
}
void loop()
{
if (digitalRead(BUTTON) == LOW)
{
digitalWrite(LED_1, HIGH);
digitalWrite(LED_2, LOW);
}
else
{
alert();
delay(10);
digitalWrite(LED_1, LOW);
digitalWrite(LED_2, HIGH);
ledcWriteTone(CHN, 0);
}
}
void alert()
{
float sinVal;
int toneVal;
for (int x = 0; x < 360; x += 10)
{
sinVal = sin(x * (PI / 180));
toneVal = 2000 + sinVal * 500;
ledcWriteTone(CHN, toneVal);
delay(10);
}
}