How can i generate a series of random number to select multiple positions of an array?
I need to set on which loop, a random number of servos moving and also on a random order.
So far I managed to do it like this but I can't seem to find a way to associate a random number with which of servos to move.
code
#include <Servo.h>
/////////////
Servo s2; // #######################
Servo s3; // # #
Servo s4; // # (2) (3) (4) #
Servo s5; // # #
Servo s6; // # (5) (6) (7) #
Servo s7; // # _ #
// #######################
/////////////
Servo exec[] = {s2, s3, s4, s5, s6, s7};
int whichMotors;
int quantatyMotor;
void setup(){
Serial.begin(9600);
s2.attach(2);
s3.attach(3);
s4.attach(4);
s5.attach(5);
s6.attach(6);
s7.attach(7);
randomSeed(analogRead(0));
}
void loop(){
quantatyMotor = random(0, 6);
for (int i=0; i <= quantatyMotor; i++){
Serial.println("I");
Serial.println(i+2);
Serial.println("QUANTATY OF MOTORS");
Serial.println(quantatyMotor+1);
whichMotors = random(0, 6);
exec*.write(10);*
- delay (100);*
_ exec*.write(40);*_
* Serial.println("MOTOR");*
* Serial.println(whichMotors);*
* }*
delay(4000);
} [/font]
---------------------------------------------------------------------------
What i need is to move for instance the 3rd and the 5th motor, afterward the 1st, the 2nd, and the 6th, and next the 1st, the 4th the 5th and the 6th.
Sometimes only one, and sometime all of them.
Any help greatly appreciated!
Cheers!