Hi, this is my first post on here. I would like some advice on what is probably a very simple thing to achieve.
I have a kinetic roof model for an exhibition, it is controlled by 5 servos attached to a rack and pinion gear.
For the exhibition I simply want to have the 5 servos all move to a random position between 0 and 180 then after ten seconds move to another random position and so on ad infinitum.
Here's the code I tried:
#include <SoftwareServo.h>
SoftwareServo myservo; // create servo object to control a servo
SoftwareServo myservo2; // create servo object to control a servo
SoftwareServo myservo3; // create servo object to control a servo
SoftwareServo myservo4; // create servo object to control a servo
SoftwareServo myservo5; // create servo object to control a servo
int potpin = A0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
void setup()
{
myservo.attach(2); // attaches the servo on pin 2 to the servo object
myservo2.attach(3); // attaches the servo on pin 2 to the servo object
myservo3.attach(4); // attaches the servo on pin 2 to the servo object
myservo4.attach(5); // attaches the servo on pin 2 to the servo object
myservo5.attach(6); // attaches the servo on pin 2 to the servo object
}
void loop()
{
myservo.write(random(0,180)); // sets the servo position according to the scaled value
myservo2.write(random(0,180)); // sets the servo position according to the scaled value
myservo3.write(random(0,180)); // sets the servo position according to the scaled value
myservo4.write(random(0,180)); // sets the servo position according to the scaled value
myservo5.write(random(0,180)); // sets the servo position according to the scaled value
delay(10000);
SoftwareServo::refresh();
}
Unfortunately this doesn't work because the servos only move a fraction toward their destination every 10 seconds. So how do I allow them to move to the final position (x seconds) and then wait (y seconds) so that x+y=10?
If anyone can help I'd be greatly appreciative ![]()
Thank,
Matt.