I have a binary water level sensor, that I would like to use to close a valve for a minimum of 5s.
The patch in the screen shot will cause the valve to close for 5s, when the sensor goes high. If the sensor continues to remain high after 5s, the valve opens. I would like the valve to remain closed for further 5s, if the sensor is high, and so on.
Can anybody help me please?
What is supposed to happen when the sensor is low? What if it goes low while valve is open? When valve is closed?
When to sensor is low, the valve is open. When the sensor goes from high to low, the valve remains open for 5s. The valve is closed, the sensor is high or the 5s delay is in effect.
Thanks for responding.
Now I’m even more confused…
Is this what you want?
Sensor low: valve open
Sensor high: valve alternates between open and closed every 5 seconds
If you want to program computers, you need to cover ALL situations. What happens if sensor is still high after valve has been closed for 5 sec? Judging from your earlier posts, the valve is supposed to open for 5 sec, then close again, repeating the cycle until sensor goes low and you leave the valve open. That is not what you are saying in your last post.
Your last post implies that valve is open when sensor is low. If sensor goes high, you close the valve for 5 sec, then open valve only after sensor goes low. That is very different functionality and requires a much different program.
Although the two sound very similar, the first keeps changing the state of the valve when the sensor is not changing, so it needs additional code to remember the current state of the valve. The second probably doesn’t need to remember the current state of the valve; it can always be calculated.
This is a solution if you want the valve open when switch is low, but force the valve closed for at least 5 sec when switch goes high (it will stay closed until switch is low AND timer has expired).
Here is one of many solutions if you want the valve open when switch is low, but the valve should alternate between open & closed when the switch is high (which seemed to be what you were asking for in your initial post—NOT a good idea if valve is letting fluid in until sensor says it is full; you will keep opening the valve while tank is already full).
The flip-flop is to remember if the valve is on or off. The count is to toggle the flip-flop every 5 seconds. The clock is only enabled if the switch is high OR the flip-flop is currently off (the not & defer nodes on the left side). If the switch goes high, it immediately resets the flip-flop (closes the valve) and resets the clock (so we get a full 5 seconds off). With each tick of the clock (every 5 sec) the valve will change (on to off or off to on) as long as the switch is high.
If the switch goes low while the valve is on, then the clock is disabled and valve will stay on. If the switch goes low while the valve is off, nothing changes until the clock ticks again & turns the valve back on. Now the valve is on and the switch is low, so the clock is disabled (so the valve stays on until the switch goes high).
Thank so much for your effort. I will give these a try.
I managed to get the attached screen shoot of the patch to give the effect I needed.