CODING HELP! UNO R3

Hi, Everyone,

I am very new to Arduino and coding in general but I’ve given it a good crack with the help of the book and the amazing internet.
Anyways the code below currently works perfectly for me. I have been able to achieve the first stage of my project consisting of two servos alternating operation to sweep to a certain position and then back again and then return to the center of their travel. However the second stage of my project, I wish to count up each full sweep(Left and Right). So for example, once one servo travels full one way and full the other way I would like to then count up 1 and the same for the other servo together so I can record the number of sweeps both the servos complete together. I have the LCD 16*2 Controller which connects directly to the Arduino Uno R3 and I am aware I may need a breadboard to connect the LCD and servos together as there may be sharing of pins. However, if anyone can please provide some assistance to achieve the full operation, that would be greatly appreciated!

#include <Servo.h>

Servo myservo1;
Servo myservo2;

int myservo1Pin = 9;
int myservo2Pin = 6;
int pos = 0; // servo position in degrees

void setup()
{
myservo1.attach(myservo1Pin = 9);
myservo2.attach(myservo2Pin = 6);
}

void loop()
{
for (pos = 0; pos <= 20; pos += 2) { // SERVO 1 goes from 0 degrees to 20 degrees // in steps of 2 degree
myservo1.write(pos); // tell servo to go to position in variable ‘pos’
delay(50); // waits 50ms for the servo to reach the position
}
for (pos = 20; pos >= 0; pos -= 2) { // SERVO 1 goes from 20 degrees to 0 degrees
myservo1.write(pos); // tell servo to go to position in variable ‘pos’
delay(50); // waits 50ms for the servo to reach the position
}
for (pos = 0; pos <= 10; pos += 2) { // SERVO 1 goes from 0 degrees to 10 degrees
myservo1.write(pos); // tell servo to go to position in variable ‘pos’
delay(50);
}
for (pos = 10; pos <= 10; pos += 2) { // SERVO 1 Pauses at 10 degrees
myservo1.write(pos); // tell servo to go to position in variable ‘pos’
delay(1);
}
for (pos =10; pos >=0 ; pos -= 2) { // SERVO 2 goes from 10 degrees to 0 degrees
myservo2.write(pos); // tell servo to go to position in variable ‘pos’
delay(50); // waits 50ms for the servo to reach the position
}
for (pos = 0; pos <= 20; pos += 2) { // SERVO 2 goes from 0 degrees to 20 degrees // in steps of 2 degree
myservo2.write(pos); // tell servo to go to position in variable ‘pos’
delay(50); // waits 50ms for the servo to reach the position
}
for (pos = 20; pos >= 0; pos -= 2) { // SERVO 2 goes from 20 degrees to 0 degrees
myservo2.write(pos); // tell servo to go to position in variable ‘pos’
delay(50); // waits 50ms for the servo to reach the position
}
for (pos = 0; pos <= 10; pos += 2) { // SERVO 2 goes from 0 degrees to 10 degrees
myservo2.write(pos); // tell servo to go to position in variable ‘pos’
delay(50);
}
for (pos = 10; pos <= 10; pos += 2) { // SERVO 2 Pauses at 10 degrees.
myservo2.write(pos); // tell servo to go to position in variable ‘pos’
delay(1);
}
for (pos =10; pos >=0; pos -= 2) { // SERVO 1 goes from 10 degrees to 0 degrees AND PROCESS REPEATS.
myservo1.write(pos); // tell servo to go to position in variable ‘pos’
delay(50); // waits 50ms for the servo to reach the position
}
}

What variable do you want to periodically increment? Each iteration of loop() seems to move the servos the way you want, so once per iteration of loop(), you'd increment that counter.

Hi Paul

Is it possible with the Arduino Uno to increase the counter by one increment every time either myservo 1 or myservo 2 pauses at the center of its travel? The project is to test the durability of a switch. So the servos are there to mechanically operate the switch on its X and Y axis and I wish to count in sequential order every time a full travel is complete.

What is the simplest method to achieve this?