/*_________________________________________________ * * U C I C R I T T E R S T U D Y G R O U P * L E S S O N 3 * Working with Servos * * * PURPOSE: * DEMO HOW TO CONTROL STANDARD SERVO (0-180 ROTATION) * Shows counted loop structure increment/decrement */ //---must use servo.h library that comes with Arduino IDE #include //---instantiate new servo object Servo myServo; //--- store current servo positionition int position = 0; void setup() { myServo.attach(10); // control the servo on pin 10 } void loop() { //---sweep clockwise from 0-180 degrees in 1 degree increments for (position = 0; position <= 180; position += 1) { myServo.write(position); delay(10); //controls sweep speed } //---sweep back the other direction for (position = 180; position >= 0; position -= 1) // -= means subtract 1 from position variable to count backwards { myServo.write(position); delay(10); } }