Hi all,

I am completely new to Arduino but have spent the last few weeks working through the book and familiarising myself with how it works.

For part of my project, I need to make 3 motors vibrate one after another, and then back again (i.e. A, B, C, B, A etc.). I would like the first one to start vibrating, then the second one to start vibrating before the first one has faded out, then the third one to start vibrating before the second one has faded out (by this point the first one will have faded out) and so on. I am currently fading in/out LEDs to replicate this scenario. I am using Arduino Uno.

Unfortunately, I cannot quite get the timing right and this means the middle LED (B) does not seem to fully fade in and out (and when we used the motors with this code, it meant that the middle motor wasn’t vibrating very much). I have been randomly editing the numbers in an attempt to solve my problem.

I would very much appreciate some help on finding out why my code isn’t working - I might be missing an obvious solution! Please see my code below. Thank you very much in advance!

```
// Declaration of variables and matrices
int NumMotors = 3;
int incomingByte[3]; //for incoming serial data
int Motors[3] = {
0, 1, 2 }; // Motor numbers that correspond to ProcessingGUI
// Declaration of pin numbers
// Motors
int motorPinA = 9; // the first motor connected to pin 9
int motorPinB = 6; // the first motor connected to pin 6
int motorPinC = 3; // the first motor connected to pin 3
int motorList[3] = {
motorPinA, motorPinB, motorPinC};
int i = 0;
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
// Set all motorPins as output
for (int i=0; i<NumMotors; i++)
pinMode(motorList[i], OUTPUT);
}
void loop() {
float tstart = millis()/1000.0;
mean[motor] = 127.5;
//Activate the motors with a sine wave at specified frequency and amplitude.
float t = millis()/1000.0;
delay(50);
analogWrite(motorPinB,127.5 + 127.5 * sin(0.3*2.0*PI*t));
delay(50);
analogWrite(motorPinC,127.5 + 127.5 * sin(0.3*2.0*PI*t-1.57));
delay(50);
analogWrite(motorPinB,127.5 + 127.5 * sin(0.3*2.0*PI*t-3.14));
delay(50);
analogWrite(motorPinA,127.5 + 127.5 * sin(0.3*2.0*PI*t-4.71));
delay(50);
}
```