Hello,
I am still in the process of creating a logic for my program so I cannot provide any code.
I would like to ask for some expert advice on how can this be done.
Problem:
I am working on a project with mechanism that uses several stepper motors and limit switches.
I wonder how you could program Arduino for it to record a sequence of events.
I have different control modes (e.g. FORWARD, REVERSE, RESET et.al)
Example:
In FORWARD:
The sequence should be, and the mechanism should
- Touch Limit Switch 1
- Touch Limit Switch 3
- Touch Limit Switch 4
In REVERSE:
The sequence should do below
- Touch Limit Switch 4
- Touch Limit Switch 3
- Touch Limit Switch 1
In RESET :
The sequence should be, and the mechanism should
- Touch Limit Switch 2
There are other control modes but let us just focus on three above.
I am able to move the mechanism to touch the different switches using AccelStepper library.
Now, I need to do the following:
- Record the sequence of events and verify that this happens in the desired sequence
- If after 10 seconds (timeout) and the desired touching of the limit switches did not happen then sound the alarm ( buzzer)
Challenges:
Stepper motor movement to touch the limit switches takes some time so there will be some waiting time.
My first thought is to create a list of sequence arrays (my pseudocode)
forwardSequenceArray = [1,3,4]
reverseSequenceArray = [4,3,1]
resetSequenceArray = [2]
And for each activation of the control mode, I would record the sequence of events and compare it against the 3 arrays above. I am not sure if this is optimal or if there is a more Arduino savvy way of doing this.
I am still thinking about how to implement a timeout.
Any ideas? I am all ears.