// Finger 1
#include <Servo.h>
Servo fingerServo;
void setup() {
fingerServo.attach(12); // Attaches switchboard
}
Servo thumbfingerServo; // create servo object to control the robotic finger
int clockwiseSwitch = 2; // digital pin for the clockwise switch
int counterclockwiseSwitch = 3; // digital pin for the counterclockwise switch
void setup() {
thumbfingerServo.attach(22); // attaches the servo on pin 22
pinMode(clockwiseSwitch, INPUT); // set the clockwise switch pin as an input
pinMode(counterclockwiseSwitch, INPUT); // set the counterclockwise switch pin as an input
}
// This loop will allow for the code to read the input from teh switches
void loop() {
// Read the state of the clockwise switch (HIGH or LOW)
int clockwiseState1 = digitalRead(clockwiseSwitch);
// Read the state of the counterclockwise switch (HIGH or LOW)
int counterclockwiseState1 = digitalRead(counterclockwiseSwitch);
// Move the finger based on the switch states
while (clockwiseState1 == HIGH && thumbfingerServo.read() < 180) {
moveFingerClockwise();
clockwiseState1 = digitalRead(clockwiseSwitch);
}
while (counterclockwiseState1 == HIGH && thumbfingerServo.read() > 0) {
moveFingerCounterclockwise();
counterclockwiseState1 = digitalRead(counterclockwiseSwitch);
}
}
void moveFingerClockwise() {
thumbfingerServo.write(thumbfingerServo.read() + 1); // Increment the current position
delay(50); // Add a delay for smoother movement
}
void moveFingerCounterclockwise() {
thumbfingerServo.write(thumbfingerServo.read() - 1); // Decrement the current position
delay(50); // Add a delay for smoother movement
}
If you have any idea as to why the delay can take 5 second or up to a few minutes, please send recommendations. Is it something I forgot to add or is there a problem with what is written?