Hi all this is my first post on here sorry if this is the wrong place for this.
I'm writing my own code for an autolevel ecu that will turn on relays to adjust airbag suspension.
So far i have managed to get all the names down and set up an automatic calibration code that will record min and max sensor values on each corner of the vehicle through the full range of suspension travel. This then is written to the eeprom for future use so when car is turned off it will still remember these values etc.
Heres a few variables i have named.
a front right sensor named (frs) a target height for that front right sensor (frt) 3 conditions for the front right sensor - frhigh - frlow - frstable
I have been able to make it constantly adjust the height of the car to reach the target value and set frstable as true (not turning on any relays to bags)
Here is where my knowledge ends and need some help.
If frs is not within the boundary frt+frt*0.1 or frt-frt*0.1 then i want a timer to start from here i want it to check if the sensor frt remains outside that boundary for 20 seconds if at the end of 20 seconds it is still outside the boundary i want it to then adjust height until the frstable condition is true then im going to guess reset timer and continue checking
This is so if you go over a bump and the height changes the car doesn't instantly try change height for that 1 little bump it needs to remain outside the allowed range for 20 seconds before it makes changes.
I can attach my code if needed just after some help on where to start.
I'm not sure how i go about it but id also preferably like it to do the following assuming the car is lower than target range
check if a side is not within the range note if it is high or low (in this case too low) count 20 seconds if its still outside the range (still too low) raise the car until the sensor value is within the range then reset timer and continue checking
needs to be able to do this for all 4 corners and independently so if 1 corner is down then 10 seconds later the other corner is down i want it to act on the first corner after 10 seconds and the second corner after a further 10 seconds.
Thanks for any help or guidance. I can post the code i have now if required. Cheers