john green
Member
To troubleshoot a problem, I wish to remotely determine and indicate whether an object moves more than a small distance left to right or visa versa.
Using optical sensors for example, I can easily achieve digital outputs (similar to a shaft encoder) that will give high outputs in one order or the other but it is recognised that differing speeds of movement will result in a variable pause between the signals.
The first part of an imagined code would determine which of two inputs (eg: left or right) has been first triggered and would then need to wait for the second input to be triggered during a specified period of time - lets say 2 seconds - to determine the direction of movement or, if this does not appear because the movement is too small, to return to the waiting state.
If it was certain that the second input signal would arrive before the first signal had returned to zero I would quite easily manage but this cannot be guaranteed and I have no way of being able to ensure this condition can be met by changing the physical environment or the efficacy of the sensors.
The required program enquiry is therefore;
After a high signal is detected at input 1, is there a corresponding high signal at input 2 within two seconds of the high signal at input 1 and regardless of whether the signal at input 1 has remained high?'
If the onset of a movement from the first sensor is detected and on the assumption that the input received from the second sensor would last for a minimum 0.1 of a second, I can see that it is possible to repeat twenty times a do...loop with a pause of 0.1 second asking if the input 2 has gone high. This would certainly achieve my needs but it seems rather clumsy.
I presume there must be a much tidier way of asking 'Has the input pin 2 gone high anytime during the previous two seconds?' and I seek advice on how the far more competent experts than myself might achieve this.
Thank you.
Using optical sensors for example, I can easily achieve digital outputs (similar to a shaft encoder) that will give high outputs in one order or the other but it is recognised that differing speeds of movement will result in a variable pause between the signals.
The first part of an imagined code would determine which of two inputs (eg: left or right) has been first triggered and would then need to wait for the second input to be triggered during a specified period of time - lets say 2 seconds - to determine the direction of movement or, if this does not appear because the movement is too small, to return to the waiting state.
If it was certain that the second input signal would arrive before the first signal had returned to zero I would quite easily manage but this cannot be guaranteed and I have no way of being able to ensure this condition can be met by changing the physical environment or the efficacy of the sensors.
The required program enquiry is therefore;
After a high signal is detected at input 1, is there a corresponding high signal at input 2 within two seconds of the high signal at input 1 and regardless of whether the signal at input 1 has remained high?'
If the onset of a movement from the first sensor is detected and on the assumption that the input received from the second sensor would last for a minimum 0.1 of a second, I can see that it is possible to repeat twenty times a do...loop with a pause of 0.1 second asking if the input 2 has gone high. This would certainly achieve my needs but it seems rather clumsy.
I presume there must be a much tidier way of asking 'Has the input pin 2 gone high anytime during the previous two seconds?' and I seek advice on how the far more competent experts than myself might achieve this.
Thank you.