Adding a delay before the LED blinks?

Hi! I just singed up today, and I was wondering if anyone could help me with a question that I have. What I am trying to do is use a push button to trigger an RGB LED strip to blink. But what the problem is, I need a specific delay in the code so that when the button gets pushed, there will be a 30-second delay before the light begins blinking normally. If this makes any sense, I would really appreciate some help! Thank you!

The simple way would be to insert delay(30000); before starting the LED strip blinking. However, if the code is expected to do anything during the waiting period then a different , non blocking technique is required.

Read Using millis() for timing. A beginners guide, Several things at the same time and look at the BlinkWithoutDelay example in the IDE.

It would be easier to provide help if you posted your existing code

UKHeliBob:
The simple way would be to insert delay(30000); before starting the LED strip blinking. However, if the code is expected to do anything during the waiting period then a different , non blocking technique is required.

Read Using millis() for timing. A beginners guide, Several things at the same time and look at the BlinkWithoutDelay example in the IDE.

It would be easier to provide help if you posted your existing code

Here is the existing code:

int led_pin = 13; void setup() { pinMode(led_pin, OUTPUT); }
void loop() { digitalWrite(led_pin, HIGH); }
int delay_value = 1000; int led_pin = 13;

void setup() {
pinMode(led_pin, OUTPUT);
}

void loop() {
digitalWrite(led_pin, HIGH);
delay(delay_value); digitalWrite(led_pin, LOW);
delay(delay_value);
}

int delay_value = 1000;
int led_pin = 13;
int button_pin = 2;
void setup() {
pinMode(led_pin, OUTPUT); pinMode(button_pin, INPUT);
}
void loop() {
digitalWrite(led_pin, HIGH);
delay(delay_value);
digitalWrite(led_pin, LOW);
delay(delay_value);
int button_state = digitalRead(button_pin);
if (button_state == HIGH) {
delay_value = 100;
} else {
delay_value = 1000;
}
}

Have you tried to compile the program that you posted ?

Here it is Auto Formatted in the IDE and posted in code tags (HINT)

int led_pin = 13;

void setup()
{
  pinMode(led_pin, OUTPUT);
}
void loop()
{
  digitalWrite(led_pin, HIGH);
}
int delay_value = 1000;
int led_pin = 13;

void setup()
{
  pinMode(led_pin, OUTPUT);
}

void loop()
{
  digitalWrite(led_pin, HIGH);
  delay(delay_value);
  digitalWrite(led_pin, LOW);
  delay(delay_value);
}

int delay_value = 1000;
int led_pin = 13;
int button_pin = 2;
void setup()
{
  pinMode(led_pin, OUTPUT);
  pinMode(button_pin, INPUT);
}
void loop()
{
  digitalWrite(led_pin, HIGH);
  delay(delay_value);
  digitalWrite(led_pin, LOW);
  delay(delay_value);
  int button_state = digitalRead(button_pin);
  if (button_state == HIGH)
  {
    delay_value = 100;
  }
  else
  {
    delay_value = 1000;
  }
}

Two loop() functions, two setup() functions and multiple definitions of global variables

Did you post the right code ?

UKHeliBob:
Have you tried to compile the program that you posted ?

Here it is Auto Formatted in the IDE and posted in code tags (HINT)

int led_pin = 13;

void setup()
{
  pinMode(led_pin, OUTPUT);
}
void loop()
{
  digitalWrite(led_pin, HIGH);
}
int delay_value = 1000;
int led_pin = 13;

void setup()
{
  pinMode(led_pin, OUTPUT);
}

void loop()
{
  digitalWrite(led_pin, HIGH);
  delay(delay_value);
  digitalWrite(led_pin, LOW);
  delay(delay_value);
}

int delay_value = 1000;
int led_pin = 13;
int button_pin = 2;
void setup()
{
  pinMode(led_pin, OUTPUT);
  pinMode(button_pin, INPUT);
}
void loop()
{
  digitalWrite(led_pin, HIGH);
  delay(delay_value);
  digitalWrite(led_pin, LOW);
  delay(delay_value);
  int button_state = digitalRead(button_pin);
  if (button_state == HIGH)
  {
    delay_value = 100;
  }
  else
  {
    delay_value = 1000;
  }
}




Two loop() functions, two setup() functions and multiple definitions of global variables

Did you post the right code ?

No I accidentally posted my non-edited one. Just so you know, I am using an led strip if that makes any difference... Here is the better version:

int delay_value = 1000;
int led_pin = 13;
int button_pin = 2;
void setup() {
pinMode(led_pin, OUTPUT); pinMode(button_pin, INPUT);
}
void loop() {
digitalWrite(led_pin, HIGH);
delay(delay_value);
digitalWrite(led_pin, LOW);
delay(delay_value);
int button_state = digitalRead(button_pin);
if (button_state == HIGH) {
delay_value = 100;
} else {
delay_value = 1000;
}
}

Please see the post at the top of the forum - "How to use the forum" - then the part about posting code using the code tags - that will make it easier for others to help you