54 lines
989 B
C++
54 lines
989 B
C++
#include <Arduino.h>
|
|
|
|
#ifndef ANALAOG_OUTPUT_PIN
|
|
#define ANALOG_OUTPUT_PIN 3
|
|
#endif
|
|
|
|
namespace ToneGenerator
|
|
{
|
|
void handleToneGeneration(void *pvParameters);
|
|
|
|
bool tone_on = false;
|
|
int frequency = 220; // A4
|
|
|
|
void init()
|
|
{
|
|
pinMode(ANALOG_OUTPUT_PIN, OUTPUT);
|
|
xTaskCreate(handleToneGeneration, "handleToneGeneration", 2048, NULL, 1, NULL);
|
|
}
|
|
|
|
void handleToneGeneration(void *pvParameters)
|
|
{
|
|
int tone_duration = 100;
|
|
while (true)
|
|
{
|
|
if (tone_on)
|
|
{
|
|
// tone(ANALOG_OUTPUT_PIN, frequency, tone_duration);
|
|
delay(tone_duration);
|
|
tone_on = false;
|
|
}
|
|
delay(10);
|
|
}
|
|
}
|
|
|
|
void setToneOn(bool on)
|
|
{
|
|
tone_on = on;
|
|
}
|
|
|
|
bool isToneOn()
|
|
{
|
|
return tone_on;
|
|
}
|
|
|
|
void setFrequency(int freq)
|
|
{
|
|
frequency = freq;
|
|
}
|
|
|
|
int getFrequency()
|
|
{
|
|
return frequency;
|
|
}
|
|
} |