Hi everyone, I have a question how to count the time of meeting a certain condition in arduino?
I would like to read the Ibus status and if it is> 1900 and lasts more than 2 seconds, it should give a servo signal of 1750ms and then return to the original 1500ms
I don't know how to make it count down these 2 seconds ... if it's over 1900
My code:
unsigned long timeOfLastChangeServo = 0;
unsigned long timeIBus = 0;
void servoOpen(){
if(IBus.readChannel(3) > 1900)
{
servo.attach(PB4);
servo.writeMicroseconds(1750);
timeOfLastChangeServo = millis();
}
else if(millis() - timeOfLastChangeServo > 500 and millis() - timeOfLastChangeServo < 1000)
{
servo.writeMicroseconds(1500);
}
else if(millis() - timeOfLastChangeServo > 1000)
{
servo.detach();
}
Thank you in advance for your help
Sorry for my English