//Project 10 Servo
/*
#include <Servo.h> //declare to insert Servo.h library
Servo myservo; // create servo object to control a servo
int pos = 0; //variable pos to store position of servo
void setup() {
myservo.attach(9); //attach the servo to digital pin 9.
}
void loop() {
for(pos = 0; pos < 180; pos += 1){ //servo turns from 0 to 180 in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // wts 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) { // servo turns from 180 to 0 in steps of 1 degree
myservo.write(pos); //tell servo to go to position in variable 'pos'
delay(15); //waits 15ms for the servo to reach the position
}
}
*/
//Project 11 controllable servo
#include <Servo.h> // insert the Servo.h library
Servo myservo; // create servo object to control servo
int potpin = 0; // connect potentiometer to digital pin0
int val; // variable value to read value from analog pin
void setup() {
myservo.attach(9); //Attach the servo on pin 9 to the servo object.
}
void loop() {
val = analogRead(potpin); //eads the value of the potentiommeter (value between 0 and 1023)
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
delay(15); // wait for 15 ms to turn to certain position
}