OUT_Servo+2xSwitches01 by yasusanto

This sketch is missing a short description
**Servo and 2x Momentary Switches 01** This is a simple program to make Arduino to read signals (on/off) from two momentary switches (it reads signals about every 10 milliseconds). The program then instruct Arduino to move the servo to one of 3 predefined positions according to the combination of switches pressed. - If both switches are pressed, the servo moves to the middle of its range (90 degree). - If switch 1 is pressed, it moves to the minimum angle defined by “servomin” (about 0 degree but usually more) - If switch 2 is pressed, it moves to the maximum angle defined by “servomax” (about 180 degree but usually less) **rotateServo** is a custom function to convert a degree set in the main routine (loop) into a pulse length and send the pulse to the servo motor. The servo needs to receive the pulse repeatedly until it completes its rotation. This is why “rotateServo” function is repeated by 30 times to make sure the servo receives the required pulse until it completes the rotation. 30 times often is more than the servo requires, but it will guarantee that the servo can complete its rotation for all circumstances. Arduino has its own function to control servos, which is much more useful if you want to manage multiple servos or your program is more complex and required to manage a number of other time-critical operations, but the problem is that it disables PWM output on pins 11 and 12. This is problematic if you want to combine RGB-LEDs with servo motors. If you are interested to learn more about Arduino’s Servo library, see “[Servo](https://www.arduino.cc/en/Reference/Servo)” library in Arduino’s language reference. ![enter image description here](http://coadaptable.com/dnb603/dnh603_light+sound+motion_switches.png "enter image title here")

Embed This Sketch

Use the following HTML code to embed the sketch code above in your blog or website.

<iframe style="height: 510px; width: 100%; margin: 10px 0 10px;" allowTransparency="true" src="https://codebender.cc/embed/sketch:106865" frameborder="0"></iframe>

Embed The Serial Monitor

You can also embed the Serial Monitor section! Just use this HTML code.

<iframe style="height: 510px; width: 100%; margin: 10px 0 10px;" allowTransparency="true" src="https://codebender.cc/embed/serialmonitor" frameborder="0"></iframe>