I would like to play two frequencies (522 and 660) at the same time on a buzzer using an esp32.
I have tried these different methods:
void loop()
{
unsigned long t = micros();
if(t % 261 <= 10) //for approximation
{
firstWave = !firstWave;
}
if(t % 330 <= 10)
{
secondWave = !secondWave;
}
if(firstWave && secondWave)
{
digitalWrite(13, HIGH);
}
else
{
digitalWrite(13, LOW);
}
}
This one resulted in absolutely no sound at all. Then I tried forcing it with FreeRTOS without thinking too much...
void secondWave(void* p)
{
while(true)
{
delayMicroseconds(330);
digitalWrite(13, HIGH);
delayMicroseconds(330);
digitalWrite(13, LOW);
}
return;
}
void setup()
{
xTaskCreate(secondWave, "wave", 10000, NULL, 1, NULL);
}
void loop()
{
delayMicroseconds(261);
digitalWrite(13, HIGH);
delayMicroseconds(261);
digitalWrite(13, LOW);
}
This didn't work... but who is watchdog and why is he getting triggered.
I do not want to buy a second buzzer. I do not want to buy a different card.
please help, thanks