OUT_Servo+2xSwitches02 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 forward, backward, or a predefined position 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 the servo counterclockwise by a predefined angle (roughly by -2 degrees) - If switch 2 is pressed, it moves the servo clockwise by a predefined angle (roughly by 2 degrees) **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 to turn the servo to a predefined position is repeated by 20 times to make sure the servo receives the required pulse until it completes the rotation. The function used to turn the servo clockwise and anticlockwise is not repeated because each function call only turns the servo by a small amount and single pulse is likely to be sufficient. 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:106864" 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>