I have what I think is a pretty basic question that I couldn't find an answer to in the Forum. I have a Beam sensor that once tripped triggers two motions on an actuator. If the sensor is triggered multiple time while the actuator is still performing it's function the actuator locks up. I can't seem to find the best way to prevent the reading of additional inputs until the actuator is finished. Code Below.
To follow up I tried something this morning. I changed the pinMode from INPUT to OUTPUT at the beginning of the movement and then switched it back at the end of the movement. This seems to work well. I don't know why because as you pointed out the delay should be preventing inputs during the motion but it did seem to work. I'll keep learning about State machines. Thanks.
Did this get resolved? I'm curious so am trying to run the sketch in post #4. With few details of your circuit, (sensor?, outputs?) I've connected your ENA, IN1 and IN2 pins to amber, red and green LEDs respectively. Resultant behaviour not making much sense. So - assuming you're still interested - can you please tell us:
What should happen?
What sensor are you using? Mine is a PIR, with its HIGH period set to the minimum, about 6 s, and is running in non-retriggerable mode.
This is hooked up to a Beam sensor.
When the beam sensor trips it turns on an actuator that extends for a set period of time, stops for a set period of time, and then lowers for a set period of time. The actuator is lifting another motor that spins a shaft when its down and lets the shaft freespin when it's up. So far, the coding works out just fine. What I found is that if I don't Turn the sensor input OFF once it triggers and keep it OFF until the sequence is complete, any additional sensor triggers tend to mess up the sequence and either cause it to freeze up or to start over again during the middle of the sequence. I can't really explain that but that seems to be what happens.
When you see sensor activity, set a flag that says two things. One it means you are working on the process that should invoke, and second that any input should be ignored.
The other part of the loop sees it should do the response, and when it finishes, clears the flag resetting the mechanism.
if not busy and sensor input
set busy
if busy
do a step of the response
if done clear busy