Hi all,
So I have the following code:
if ((millis() - startuptime) >= 10000UL)
{
if (millis() - alarmtime >= 5000UL)
{
if (newroll > oldroll + 0.25 || newroll < oldroll - 0.25)
{ digitalWrite(BuzzerSignalPin, HIGH);
digitalWrite(Vibration1Pin, HIGH);
digitalWrite(Vibration2Pin, HIGH);
// added this
delay(3000);
digitalWrite(BuzzerSignalPin, LOW);
digitalWrite(Vibration1Pin, LOW);
digitalWrite(Vibration2Pin, LOW);
Serial.print("ERROR");
alarmtime = millis();
}
if (newpitch > oldpitch + 0.25 || newpitch < oldpitch - 0.25)
{ digitalWrite(BuzzerSignalPin, HIGH);
digitalWrite(Vibration1Pin, HIGH);
digitalWrite(Vibration2Pin, HIGH);
// added this
delay(3000);
digitalWrite(BuzzerSignalPin, LOW);
digitalWrite(Vibration1Pin, LOW);
digitalWrite(Vibration2Pin, LOW);
Serial.print("ERROR");
alarmtime = millis();
}
}
}
Just to clarify, in setup I declared that
startuptime = millis()
and defined both startuptime and alarmtime as
unsigned long
.
The values of newroll, newpitch, oldroll, and oldpitch are generated before this in the program. The full program is attached, but it is really long and I do not suggest going through it. By the way, the serial monitors show that I am getting the correct values for the variables, but the buzzer just stays on for 20sec and off for 10sec even when still. The feed from the monitors is attached in the image.
Why is the buzzer remaining on even when the values of the variables are within the range?
gy_521_send_serial.ino (38.5 KB)
Interrupt.ino (6.49 KB)