#define PIN_BUZZER 5
#define PIN_BUTTON 4
void setup () {
pinMode (PIN_BUTTON,INPUT);
pinMode (PIN_BUZZER, OUTPUT);
Serial.begin(115200);
}
void loop () {
if (digitalRead(PIN_BUTTON)== LOW)
{
alert();
}
else
{
analogWrite(PIN_BUZZER, 0);
}
}
void alert()
{
float sinVal;
int toneVal;
for (int x = 0; x < 360; x++)
{
sinVal =sin(x *(PI/180));
toneVal = 500 + sinVal * 500;
tone(PIN_BUZZER,toneVal);
delay (10);
noTone (PIN_BUZZER);
delay(1);
Serial.printf("Running %d \n",toneVal);
}
}