I think part of the problem is that I wrote "myservo.write(180);" where I should have written "myservo.write(i);". Sorry about that.
Another problem is that when you "open" the claw you start by closing it all the way.
No need to slow down the opening of the claw so the loop there is not necessary.
#include <Servo.h>
const int servoPin = 8;
const int sensorPin = A0;
int position;
Servo myservo;
void setup(){
myservo.write(0); // Open claw.
position = 0;
myservo.attach(servoPin );
}
void loop(){
openClaw();
delay(2000);
closeClaw();
delay(2000);
}
void openClaw() {
myservo.write(0); // Go to open position
position = 0;
}
void closeClaw() {
for (; position < 180; position++) {
myservo.write(position);
if(analogRead(sensorPin) > 450)
break;
}
}
[/quote]