Trouble with continuous servos

I am trying to make a Vex claw(attachment) open and close with a gear attached to a continuous servo. The problem with continuous servos of course is that they are continuous. I want the motor to spin one direction while I am pressing the attached button and the other direction while I'm not pressing the button. I also want the motor to spin for a certain time while pressing the button so that when the claw opens up completely the motor doesn't keep trying to open the claw. Also when the claw is completely closed I don't want the motor trying to close it further while the claw is already closed. I know it's kind of confusing, but I don't know how else to explain it.

Here is the code:
#include <Servo.h>

const int button1 = 2;

Servo VexM;

int val;

void setup() {
VexM.attach(9);
pinMode(button1, INPUT);

Serial.begin(9600);
}

void loop() {
val = digitalRead(button1);
if (val == LOW) {
VexM.write(20);

}
if (val == HIGH) {
VexM.write(160);

}}

I also tried this, but it just made the problem worse:
#include <Servo.h>

const int button1 = 2;

Servo VexM;

int val;

void setup() {
VexM.attach(9);
pinMode(button1, INPUT);

Serial.begin(9600);
}

void loop() {
val = digitalRead(button1);
if (val == LOW) {
VexM.write(20);
delay(1000);
VexM.write(90);

}
if (val == HIGH) {
VexM.write(160);
delay(1000);
VexM.write(90);

}}

If you removed the position awareness form the servo, and you still want position awareness, you must provide it in other ways.
Rotary encoder, limit switch, something to tell you that the servo has arrived at the desired position so that you can turn off the motor.

The problem with continuous servos of course is that they are

no longer servos

Look at File->Examples->02.Digital->StateChangeDetection. It shows how to do something "once when the button is pressed" instead of "for as long as the button is pressed" which is what you have.

Hi,
If you will be clamping odd objects in that claw you need to know when it has clamped with sufficient force, and when it has released the object.

Using a timer will not provide that sort of control.

You would be better off with a geared electric motor and monitor the motor current, you would have to provide some method the hold the claw, when it has gripped the object, when motor is turned off.

The same probably with your continuous servo. how to hold the clamp once it has gripped the item.

Tom.. :slight_smile: