I have a project which samples an accelerometer, calculates the vibration levels in velocity and acceleration and checks against alarm levels showing a green led for healthy, yellow for alert and red for alarm.
What I would like to do, after being in alarm for some time is make the red led flash to draw attention. Is there a method of doing this in the background with a timer so the Arduino can get on with other tasks and not have to concentrate on making the led flash.
Im not posting any code as its not relevant to the question. What I have works perfectly. Im just looking for a way to build on it.
Cheers, Steve
BaartCM:
I have a project which samples an accelerometer, calculates the vibration levels in velocity and acceleration and checks against alarm levels showing a green led for healthy, yellow for alert and red for alarm.
What I would like to do, after being in alarm for some time is make the red led flash to draw attention. Is there a method of doing this in the background with a timer so the Arduino can get on with other tasks and not have to concentrate on making the led flash.
Im not posting any code as its not relevant to the question. What I have works perfectly. Im just looking for a way to build on it.
Cheers, Steve
#define OneSecond 1000 // 1000 miliseconds
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
static unsigned long AlarmTimer;
if (digitalRead(AchnolageAlarmInputPin) || NoAlarm) {
AlarmTimer = millis();
}
if (millis() - AlarmTimer >= (OneSecond * 60 * 5 *)) {
// After 5 Minutes into the process Toggle the LED
static unsigned long AfterTimer;
if ((millis() - AfterTimer) >= (1000)) {//Delay Every Second
AfterTimer = millis();
digitalWrite(LEDPin, !digitalRead(LEDPin)); // Toggle LED
}
}
}
This is non blocking and should get you in the direction you are looking for
Z