Add this or somthing very like it to your code
// add the following
unsigned long motorStart = 0;
boolean motorOn = false;
int motorRuntime = 200;// length of time to run motor in millis
void doMotor(){
// motor control stuff
int curTime = 0;
if (motorOn){
curTime = millis();
if (curTime-motorStart>motorRuntime){
motorOn = false;
digitalWrite(motorPin, LOW);
}
}
void startMotor(){
digitalWrite(motorPin, HIGH);
motorStart = millis();
motorOn = true;
}
replace your "digitalWrite(motorPin, HIGH);" calls to startMotor();
and at the start of loop add a call to doMotor();
This should do the job.
Mark