Hello,
I have the following issue:
My program reads sensor values and depending on a servo motor.
If there is a boolean condition true, a function called sirene() must be started.
That means.
If the condition is true, the function sirene() will start. And after that the servo gets the position parameter. But the sirene() function has got delays in it. The sirene() function is responsible for controlling a little buzzer, that generates an alarm sirene.
That means if the condition is true, I have to wait 4 seconds to start the setServo() function.
Is there a better way to start both functions parallel?
#include <Servo.h>
int ServoPos = 0;
int RawPosition = 0;
int siren = 50;
int highNote = 660;
int lowNote = 440;
void setup()
{
pinMode(siren, OUTPUT);
myservo.attach(51);
}
void loop()
{
ServoPos = map(RawPosition, 500, 1500, 55, 125); //min. angle 55° max angle 125°
if (CONDITION)
{
sirene(true);
setServo(ServoPos);
}
else
{
sirene(false);
setServo(90);
}
}
void setServo(int position)
{
myservo.write(position);
}
void sirene(boolean value)
{
if (value)
{
tone(siren, lowNote, 1000); // wait for a second
delay(1000); // wait for a second
tone (siren, highNote, 1000); // wait for a second
delay(1000); // wait for a second
}
}