In this assignment, we decided to use Linkage Example#1 on the website for moving the ducks forward and backwards. Also, we automated the clock using a servo motor and set the delay between each round of the clock to 500ms.
Video: http://www.youtube.com/watch?v=49NZljqS234
Components:
1 Arduino Uno Microcontroller
1 Bread Board
1 Servo Motor
Connecting Wires
3 Ducks
Wood and screws to make the linkage
Hard board base
Other stationaries for decoration
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(7); // attaches the servo on pin 7 to the servo object
}
void loop()
{
for(pos = 0; pos < 130; pos += 1) // goes from 0 degrees to 130 degrees
{ // 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
}
delay(500); //wait for some time before going back
for(pos = 130; pos>=1; pos-=1) // goes from 130 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
delay(500); //wait for some time before going back
}
- Login to post comments