This code will provide me with a 500 millisecond delay. But my problem: The value is not monitored during the 500 milliseconds.If the value drops below 522 within the 500 millisecond, and is back above 522 at the 500 millisecond point, the LED1 will switch on anyway.It also delays the rest of the code.I'm basically looking for an old-fashioned time delay relay function.Sorry for comparing the Arduino with a PLC.

nicolaas44

Toby and Arch,Thanks for your replies.@ Toby, Your code is switching of the LED too fast, and holding up the rest of my code, but it works! @ Arrch, how can I put extra code inside to avoid blocking the processor?I don't completely understand how to translate your code to my script. (I'm pretty new with C++).

Have a look at the blink without delay example in the IDE.It should give you some ideas.

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.Do not send technical questions via personal messaging - they will be ignored.I speak for myself, not Arduino.

nicolaas44

It is quite a long story. (Sorry for being complicated).The goal is to translate audio signals to optical signals.The first thing i'm trying is to make a optical heart-beat checker. It is a medical project I'm trying with my brother (who is a doctor). The second step wil be to dedect breathing noise.I made a amplifier filter to take the low frequency, and move it around the 2,5V on one of the inputs. I was able to display the sound on 8 LED's. However the LED's also display the background noise. So I try to make them to react on either the positive or negative side of long wave. (Low frequency heart beat).That is were I need the time delay for. The LED's should only react to a long wave.Below some messy attempts. I try with "Level_LED1" first.

/* TubeChecker software. Use anelog inputs to analize hartbeat and breathing sounds, and than dispaying the result usin LED's. Writen by nicolaas Hartman, ENINN. V0_2 modifications: Make heartbeat signal more sensitive. V0_3 modifications: Time delay to filter out low frequency V0_4 modifications: New experimental Time delay to filter out low frequency */

tobyb121

May I suggest a low pass filter, either a simple moving average in the code, or a hardware filter are easy to implement.The method you've described might work, but to get the best results a filter will be much better.