#include Servo myservo; // create servo object to control a servo int potPin = 2; // analog pin used to connect the potentiometer int ledPin = 13; // select the pin for the LED int val; // variable to read the value from the analog pin void setup() { myservo.attach(9); // attaches the servo on pin 9 to the servo object pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT } void loop() { val = analogRead(potPin); // reads the value of the potentiometer (value between 0 and 1023) //motor control val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180) myservo.write(val); // sets the servo position according to the scaled value //led control digitalWrite(ledPin, HIGH); // turn the ledPin on delay(val); // waits for the servo to get there digitalWrite(ledPin, LOW); // turn the ledPin off //delay(val); // stop the program for some time } /* int potPin = 2; // select the input pin for the potentiometer int val = 0; // variable to store the value coming from the sensor void setup() { } void loop() { val = analogRead(potPin); // read the value from the sensor delay(val); // stop the program for some time } */