Useless Box with 5 Switches

Hello,

I am designing a useless box in a circular direction with 5 switches; one servo to rotate and the other for the arm.
Currently, I am stuck to make the arm turn off the switches in the same order. I am trying to use arrays to store the order, but I cant figure it out so could anyone please let me know how to do it properly ?

Thanks.

With very little info to work with...

i'd suggest capturing & keeping track of the time (milllis) when each switch is triggered by the user, then you can figure out the order (and the interval if required).

By the same token, if the user loses interest, you'd timeout and begin the 'switch off' sequence (or after the last possible switch has been set).

The unswtch sequence would effectively be a playback of the capture sequence..

This becomes more complex if the user 'fakes' a switch toggle - either putting the switch back, or other unexpected action.
Keep in mind that you could make the whole sequence more interesting by allowing on or off as the trigger state.

Break your code into separate chunks and functions... get them working separately, then tie it all together..
e.g switch capture, user timeout, auto-unswitch sequence etc.

No need to keep track of the time to work out the order.

As a switch is activated add its switch number to an array. If the uses toggles a switch off after turning it on then record a dummy value in the array, perhaps 0xFF. When you want the machine to start working then read the switch numbers from the array, ignore the 0xFF entries, and turn off the associated switch.

You could make things easier by recording the angle required to turn the rotation servo in the array instead of the switch number as an alternative to using the switch number as an index to an array of angles.

Time - of course not, unless you want to play the action back in the same manner... ideally with slightly 'flakey' timing in the same sequence to make the box look intelligent.

The simple alternative as you suggest, is just to keep track of switch order in an array, indexed in the order they occur.

My proposed scheme has snag if the user changes their mind because the entry to activate the switch is not removed from the array.

Can you guys help me with the code like how to store the positions or values in am arrays?
Thanks

Pseudo code

declare an array of bytes called switchOrder[]
arrayIndex = 0

start of loop()
  if a switch becomes closed
    switchOrder[arrayIndex] = switch number
    increment arrayIndex
  end if
end of loop()

You will find plenty of sites on the Web that describe how to declare an array.

I understand that but I dont get how to write the position to the servo in order from the array.

Each switch position corresponds to a servo rotation.
You make an array where the contents of the array are the servo position and the position in the array corresponds to the switch number.

For example suppose switch 2 has an angle of 45 degrees then an array called say servoPos would have the value 45 in the array index 2.

Then suppose the switch number is in a variable called switch then do a servo write using servoPos[switch] as the calling value.

If the radial positions of the switches are evenly spaced, you could calculate the servo position mathematically.
If they are arbitrarily spaced, it's probably easier to use a separate array that holds the n servo values needed to match the n switch positions.

So now you have two arrays... one to keep track of the switch 'order' (and optional timing), and one that lets you look up the servo position when a particular switch needs to be re-flipped.