Student Question...motor on off repeatedly

Greetings;

My assignment says:

2.For every push of a button a LED should light up until all 4 LEDs are lit.
3.On the fifth button push, all LEDs should turn off.
4.On the first button push the motor should start to run constantly.
5.On the second push the motor should turn off
6.On the third push the motor should start to pulse constantly, off and on, off and on with a suitable delay between the two.
7.On the 4thbutton push the motor should run constantly again.
8.With the 5thbutton push the motor shuts off

I am having a hard time with #6.......with the motor pulsing on and off with a delay.

I can get it to turn on and then off, but not pulse.

void loop() {
buttonState = digitalRead(button); //read button pin
if(buttonState != lastButtonState) { //compare current state to last state
if(buttonState == HIGH) { //button is pressed
buttonPushCounter++; //Increments the counter
Serial.println("on");
Serial.print("number of button pushes: "); //displays count for refernce
Serial.println(buttonPushCounter);
}else{
Serial.println("off");
}
delay(50); //delay to avoid bounce
}
lastButtonState = buttonState; //save current state for next loop
if (buttonPushCounter >= 1){
digitalWrite(ledPin[0], HIGH);
digitalWrite(motor, HIGH);
} else {
digitalWrite(ledPin[0], LOW);
digitalWrite(motor, LOW);
}
if (buttonPushCounter >= 2){
digitalWrite(ledPin[1], HIGH);
digitalWrite(motor, LOW);
} else {
digitalWrite(ledPin[1], LOW);
digitalWrite(motor, LOW);
}
if (buttonPushCounter >= 3){
digitalWrite(ledPin[2], HIGH);
} else {
digitalWrite(ledPin[2], LOW);
}
if (buttonPushCounter >= 4){
digitalWrite(ledPin[3], HIGH);
digitalWrite(motor, HIGH);
} else {
digitalWrite(ledPin[3], LOW);
digitalWrite(motor, LOW);
}
if (pushButtonCounter == 5){
digitalWrite(motor, LOW);
buttonPushCounter = 0;
}
}

jlocks:
On the third push the motor should start to pulse constantly, off and on, off and on with a suitable delay between the two.

to have it pulsing you could try something like that in your loop:
let create a global variable motor_pulse=0;

if (buttonPushCounter >= 2){ //sorry did quite figure out which count it is in your code! :stuck_out_tongue:
if(motor_pulse==0){
//motor ON
//motor_pulse=1
}
else{
//motor OFF
//motor_pulse=0
}
//delay(x); // but preferably use millis() if you can since u have many this going on

}

That may work

Hmm. All your code is in the "do this when the button gets pushed" block. To make the motor pulse, you will need code outside that block that says "if we are in #6, then check the current time to see if it's time to turn the motor on/off".