I'm using the 'Servo.h' library to control multiple servos (for model railway signals). I've declared the servos as 'Servo Sig1' (then 2, 3 &4) and attached them to the relevant pins.
However, in the code when I want to write to a specific servo, I need the servo to be inserted as a variable dependent upon a button pressed.
i.e.
Sig1.write(angle) //where 'angle' is a variable
My problem is that if I try to insert the variable for the 'Sig1', I get an error. For example:
Sig(sigNo).write(angle)
How should I write this to allow me to insert any one of 4 servos (Sig1, Sig2, Sig3 or Sig4) without causing an error?
Then use Sig[0] in place of Sig1, Sig[1] in place of Sig2, Sig[2] in place of Sig3 and Sig[3] in place of Sig4. The number in the square brackets can be a variable.