# How to run multiple DC motors in different patterns?

I am a complete novice in programming and I hope someone could guide me here. I am doing a haptic research project, where 8 DC coin vibrating motors would be fitted on the fingers of subjects (excluding thumbs), and the subject has to respond the number of fingers they feel the vibrations on.

Every trial has to have a different pattern of outputs, say: in first trial, 4 motors are activated-motor 1, motor5, motor8 and motor 3. In a single trial, the motors have to have a common delay of 150 ms and 4 seconds break after next one starts.

My question is, that in 8 motors, there are 255 different activation patterns possible. How do I define all these 255 patterns and randomise their sequence? I am using the mega board and connecting each motor to a PWM pin and all having a common ground.

Here is a sample code with 3 such combinations (only seven motors are connected here):

``````#define viboutpin 2
#define viboutpin1 3
#define viboutpin2 4
#define viboutpin3 5
#define viboutpin4 6
#define viboutpin5 7
#define viboutpin6 8

void setup() {
pinMode(viboutpin,OUTPUT);// define a pin as output
pinMode(viboutpin1,OUTPUT);
pinMode(viboutpin2,OUTPUT);
pinMode(viboutpin3,OUTPUT);
pinMode(viboutpin4,OUTPUT);// define a pin as output
pinMode(viboutpin5,OUTPUT);
pinMode(viboutpin6,OUTPUT);
}

void loop() {
digitalWrite(viboutpin,HIGH);
digitalWrite(viboutpin1,HIGH);
digitalWrite(viboutpin2,HIGH);
digitalWrite(viboutpin3,HIGH);
digitalWrite(viboutpin4,HIGH);
digitalWrite(viboutpin5,HIGH);
digitalWrite(viboutpin6,HIGH);
delay(150);
digitalWrite(viboutpin, LOW);
digitalWrite(viboutpin1,LOW);
digitalWrite(viboutpin2,LOW);
digitalWrite(viboutpin3,LOW);
digitalWrite(viboutpin4,LOW);
digitalWrite(viboutpin5,LOW);
digitalWrite(viboutpin6,LOW);
delay(2000);

digitalWrite(viboutpin2,HIGH);
digitalWrite(viboutpin6,HIGH);
delay(150);
digitalWrite(viboutpin2,LOW);
digitalWrite(viboutpin6,LOW);
delay(2000);

digitalWrite(viboutpin4,HIGH);
delay(150);
digitalWrite(viboutpin4,LOW);
delay(2000);
}
``````