Hello everybody and thanks for your help so far.
This time different than before I would like to ask your opinion on some code. I would appreciate if you tell me if you have a simpler, better idea on how to implement the following:
I have a sensor that goes ON or OFF. I want to check the sensor and do nothing while it is OFF. Then when it gets ON the logic of the code advances. This is quite simple as in
however, to complicate things this sensor can have some kind of flickering, meaning it can sometimes gives bad readings. So I want to modify the above code to advance the logic only when the sensor goes ON for at least 5 ms. I can use the functions wait_set and wait_check that sets a waiting time
while(sensor==OFF); //holds it until it goes ON
so I wrote something like
Anyhow, it seems awfully complicated.
while(sensor==OFF); //hold it
wait_set(5); //set a wait of 5 miliseconds
if(sensor==OFF) continue; //if it was flickering go to the start of the do loop
while((sensor==ON)&&!(wait_check());// wait for the sensor to be ON for 5 miliseconds
Any ideas on how to implement this in a simpler way(if there is one) will be greatly appreciated