Saturday, January 16, 2016
Project #2: Arduino Timelapse Auto-Rotator
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
int potPin = 1;
int val = 0;
void setup() {
myservo.attach(8); // attaches the servo on pin 9 to the servo object
Serial.begin(9600);
}
void loop() {
val = analogRead(potPin);
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
val = analogRead(potPin);
myservo.write(pos);
Serial.println(val*10);// tell servo to go to position in variable 'pos'
delay(val*10); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
val = analogRead(potPin);
myservo.write(pos);
Serial.println(val*10); // tell servo to go to position in variable 'pos'
delay(val*10); // pot controls delay
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment