Crawler with a balsa wood hinged arm, cork foot, and body from the box in which it came. The code sweeps the servo through the extreme positions and the potentiometer controls speed of movement.
Code below:
// Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.
// Modified by Justin Wang, 14 October 2011
// Potentiometer controls speed.
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int servoPin = 7; // Control pin for servo motor
int potPin = 0; // select the input pin for the potentiometer
int pos = 0; // variable to store the servo position
int delayTime = 10; // variable to store potentiometer value
void setup()
{
myservo.attach(servoPin); // attaches the servo on pin 9 to the servo object
Serial.begin(9600); // connect to the serial port
}
void loop()
{
delayTime = analogRead(potPin); // read the value from the sensor, between 0 - 1024
delayTime = map(delayTime, 0, 1024, 20, 5); // map potentiometer values to delayTime
for(pos = 20; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(delayTime); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(delayTime); // waits 15ms for the servo to reach the position
}
Serial.println(delayTime);
}
Video of the crawler in action.