Hi,
int pos = 0; // variable to store the servo position
You need one for each servo - each with a unique name.
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
You need to assign each servo object the pin number that the servo is attached to.
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
During a delay, the controller does nothing else, so for the 15ms, it's out to lunch and won't handle any other servo or even the simplest 1+1.
It is clearly just a quick piece of code to demo the simplest use of a servo. For running 4 servos plus the US, in a loop, you must do something like:
(Pseudo code)
Do
Get US reading
If People_Detected = TRUE Then
Call ServoRoutine(S1, S2, S3, S4)
End If
Loop
Proc ServoRoutine(S1, S2, S3, S4)
myservo1.write(S1)
myservo2.write(S2)
myservo3.write(S3)
myservo4.write(S4)
End Proc
Or the latter part may include a series of timed moves.
You'll need to decide when to stop the action and return the servos to whatever you call the start position as well - eg. nn seconds after the last detection of people, or just after a certain time from initial detection (perhaps with another preconfigured delay before it's able to start over).
Is this a standard part of the curriculum?
(I've seen so many similar posts and blogs, primarily from art students though, that pretty soon, an exhibition of static art will be considered cutting edge, with the "new" concept of resting your eyes and soul )