Hello,
I'm rather confused as to how to get the arduino to randomly pick to move 1 servo 180 degrees, 2 servos 180 degrees, or all 3 servos 180 degrees.
This is the current code I'm using which allows all 3 servos to move simultaneously. Would it be best to somehow make an array of loops? Can that even be done?
#include <Servo.h>
Servo myservo3; // create servo objects to control servo s
Servo myservo5;
Servo myservo6;
int ServoPosition3 = 0;
int ServoPosition5 = 0;
int ServoPosition6 = 0;
void PrintPosition() {
Serial.print("Motor position is: ");
Serial.print(ServoPosition3);
Serial.println(" degrees.");
}
void setup() {
myservo3.attach(9); // attaches the servo on pin 3 to the servo object
myservo5.attach(10); // attaches the servo on pin 5 to the servo object
myservo6.attach(11); // attaches the servo on pin 6 to the servo object
// start serial port at 9600 bps:
Serial.begin(9600);
}
void loop() {
ServoPosition5 = 185 - ServoPosition3;
ServoPosition6 = ServoPosition3;
myservo3.write(ServoPosition3); // tell servo to go to position in variable 'ServoPosition'
myservo5.write(ServoPosition5);
myservo6.write(ServoPosition6);
PrintPosition();
delay(4); // wait for servo to move
if(ServoPosition3 == 0) {
delay(random(1000, 50000)); // wait for servo to move if moving 180 degrees
}
ServoPosition3 = ServoPosition3 + 7; // send servo to next position
if(ServoPosition3 > 185) { // reset position if max. rotation reached
ServoPosition3 = 0;
delay(random(1000, 50000)); // pause to let sero return
}
}