Making Servo Motor Automatically Move Based on Input
So you have a "number" and you want to set the servo to some angle. The logic is very simple:


If number is 0 then set angle to 90
If number is 1 then set angle to 45


etc.

How you "get" the number hasn't been specified, so I will assume you just have an integer with a value between 0 and 5 inclusive.

Setting a servo's angle is as simple as writing that angle to the servo:

servo.write(45); // Set the angle to 45 degrees


So how do you join the two together?  Well, there's three different ways that spring to mind.


A string of if statements
A switch construct
An array


The first one is just like the bullet points above, just written as C:

if (number == 0) servo.write(90);
if (number == 1) servo.write(45);
... etc ...


The second method is very similar but can be more efficient when you know you only ever select one item from a list of options.  Read this to see how: http://hacking.majenko.co.uk/time-to-make-a-switch

The third option, the array, is especially good when you have a lot of options to manage and they are all the same result with a different value:

const int angles[6] = {90, 45, 315, 0, 0, 0};

// ... later ...
servo.write(angles[number]);