user15278: sorry if I sound incompetent, but I know nothing about coding. I have a group project where I must sort various balls into different tracks. The final issue I have is that I must use an arduino for this portion. However, none of us know how to program, and the only experience we have is from doing the lessons from adafruit (copy and paste written code). 
What I am attempting to do is attach a paddle to the tip of a high torque servo motor. I will then automatically feed the servo signals, ranging from 0 to 5. Each signal tells which position for the servo to turn to. Could anyone please help guide me in how to write this code? I was thinking of using 
this guide for my motor. However it uses a POT. My project must be completely automated. The positons also are all within 180*. 
Thank you!

user4143: 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]);


15278: <p>sorry if I sound incompetent, but I know nothing about coding. I have a group project where I must sort various balls into different tracks. The final issue I have is that I must use an arduino for this portion. However, none of us know how to program, and the only experience we have is from doing the lessons from adafruit (copy and paste written code). </p>

<p>What I am attempting to do is attach a paddle to the tip of a high torque servo motor. I will then automatically feed the servo signals, ranging from 0 to 5. Each signal tells which position for the servo to turn to. Could anyone please help guide me in how to write this code? I was thinking of using 
<a href="https://learn.adafruit.com/adafruit-arduino-lesson-14-servo-motors/overview" rel="nofollow">this</a> guide for my motor. However it uses a POT. My project must be completely automated. The positons also are all within 180*. </p>

<p>Thank you!</p>
 4143: <p>So you have a "number" and you want to set the servo to some angle. The logic is very simple:</p>

<ul>
<li>If number is 0 then set angle to 90</li>
<li>If number is 1 then set angle to 45</li>
</ul>

<p>etc.</p>

<p>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.</p>

<p>Setting a servo's angle is as simple as <em>writing</em> that angle to the servo:</p>

<pre><code>servo.write(45); // Set the angle to 45 degrees
</code></pre>

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

<ol>
<li>A string of <code>if</code> statements</li>
<li>A <a href="http://hacking.majenko.co.uk/time-to-make-a-switch" rel="nofollow">switch</a> construct</li>
<li>An array</li>
</ol>

<p>The first one is just like the bullet points above, just written as C:</p>

<pre><code>if (number == 0) servo.write(90);
if (number == 1) servo.write(45);
... etc ...
</code></pre>

<p>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: <a href="http://hacking.majenko.co.uk/time-to-make-a-switch" rel="nofollow">http://hacking.majenko.co.uk/time-to-make-a-switch</a></p>

<p>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:</p>

<pre><code>const int angles[6] = {90, 45, 315, 0, 0, 0};

// ... later ...
servo.write(angles[number]);
</code></pre>
