Help with blinking an led for 20 times then turn off for 4 seconds

hi, i need some help with blinking an led for 20 times then turn off for 4 seconds

Greetings,

for(int i = 0; i<20;i++){

digitalWrite(yourLedpin,1);
delay(yourdelay);
digitalWrite(yourLedpin,0);
delay(yourdelay);
}
delay(4000); // delay 4 seconds

This should work.

Thanks, i did it some minutes ago, now i need this "red led is on when button is pressed it go off, green led on and after 5 seconds the red go on" can you help me ?

Greetings,

“red led is on when button is pressed it go off, green led on and after 5 seconds the red go on”

if(digitalRead(button) == 0){
   digitalWrite(greenLed,1);
   digitalWrite(redLed,0);
   delay(5000); //Delay 5 seconds
}
else{
   digitalWrite(greenLed,0);
   digitalWrite(redLed,1);
}

I did this, but i can't test right now is it right ?
int pinButton = 8; //the pin where we connect the button
int RED_LED = 12; //the pin we connect the LED
int GREEN_LED = 11; //the pin we connect the LED

void setup() {
pinMode(pinButton, INPUT); //set the button pin as INPUT
pinMode(GREEN_LED, OUTPUT); //set the LED pin as OUTPUT
pinMode(RED_LED, OUTPUT); //set the LED pin as OUTPUT
}

void loop() {
int stateButton = digitalRead(pinButton); //read the state of the button
digitalWrite(GREEN_LED, LOW);
digitalWrite(RED_LED, HIGH);
if(stateButton == 1) { //if is pressed
digitalWrite(RED_LED, LOW);
digitalWrite(GREEN_LED, HIGH);
delay(5000);
digitalWrite(RED_LED, HIGH);
}
}

Greetings,

Your code will work this way.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.