The Robotic Gripper
Resources:
|
|
|
|
|
|
|
|
For 4 Servo classes:
For 2 Servo classes:
Write a few Sketch lines to perform a few simple arm movements.
For 4 Servo classes:
#include <Servo.h> Servo S1; // create servo object to control a servo Servo S2; Servo S3; Servo S4; const int button = 13; // button to pin 13 int currentState = LOW; // button is depressed void setup() { S1.attach(3); // assign S1 to Pin 3 S2.attach(5); // assign S2 to Pin 5 S3.attach(9); // assign S3 to Pin 9 S4.attach(11); // assign S4 to Pin 11 S1.write(90); // set servo at 90 deg position S2.write(90); // set servo at 90 deg position S3.write(90); // set servo at 90 deg position S4.write(0); // set servo at 0 deg position pinMode(button, INPUT); // set the push button as INPUT delay(3000); // pause for 3 secs } void loop() { currentState = digitalRead(button); // read the state of button if (currentState == HIGH) // if the button is pressed { S3.write(140); // 30 < angle < 150: this is to move the elevation arm at 50 degress from the intial position delay(1000); // pause for 1 sec: pause movement for 1 second // 30 < angle < 150 // pause for 1 sec // 0 < angle < 90 // pause for 1 sec // 0 < angle < 180 // pause for 1 sec // 0 < angle < 90 // pause for 3 sec } else // if the button is depressed (hint: reset to INITIAL position) { S1.write(90); // 0 < angle < 90 delay(500); // pause for 0.5 sec S2.write(90); // 30 < angle < 150 delay(500); // pause for 0.5 sec S3.write(90); // 0 < angle < 150 delay(500); // pause for 0.5 sec S4.write(0); // 0 < angle < 180 delay(500); // pause for 0.5 sec } } |
For 2 Servo classes:
#include <Servo.h> Servo S1; // create servo object to control a servo Servo S2; const int button = 13; // button to pin 13 int currentState = LOW; // button is depressed void setup() { S1.attach(3); // assign S1 to Pin 3 S2.attach(5); // assign S2 to Pin 5 S1.write(90); // set servo at 90 deg position S2.write(90); // set servo at 90 deg position pinMode(button, INPUT); // set the push button as INPUT delay(3000); // pause for 3 secs } void loop() { currentState = digitalRead(button); // read the state of button if (currentState == HIGH) // if the button is pressed { S1.write(10); // 0 < angle < 90 delay(1000); // pause for 1 sec // 0 < angle < 180 // pause for 3 sec // 0 < angle < 180 // pause for 3 sec } else // if the button is depressed (hint: reset to INITIAL position) { S1.write(90); // 0 < angle < 90 delay(500); // pause for 0.5 sec S2.write(90); // 0 < angle < 180 delay(500); // pause for 0.5 sec } } |