LED-pushbutton Flasher (Question)

Hello,
I need to use a pushbutton to light and control 8 LEDs of the same color and another LED of another color at the same time.
If the push button is pressed, the running flasher should freeze and the other color LED lights up. The flasher starts to run normally as soon as the pushbutton is released.

I have to use the command digitalWrite only 2 times max

I started with this code (used digitalWrite 3 times because I don’t know how to use it 2 times only), but how can I do it?

Please respond asap.

void setup() {
// put your setup code here, to run once:
Serial.begin(9600); // Set the Serial Baud Rate. Note:-with Upper ‘S’
int maxOut = 13;
int minOut = 5;
for (int i = maxOut; i <= inMax - 1; i–)
{
pinMode(i, OUTPUT);
}
for (int i = maxOut; i <= inMax; i–)
{
digitalWrite(i, HIGH); // Turn ON the 8 RED LEDs always
}
pinMode(2, INPUT)
}

void loop() {
// put your main code here, to run repeatedly:
buttonState = digitalRead(2); // Read the button state
if (buttonState == HIGH) // Check: if state is high
{
for (int i = maxOut; i <= inMax; i–)
{
digitalWrite(i, LOW); // Turn OFF the RED LED
}
digitalWrite(4, HIGH); // Turn ON the GREEN LED
}
}

Please read the first topics like "How to use forum", "How to attache code".

How is the button wired to D2?
It might work. What happends when You run the code?

Please respond asap.

Is there a special reason for that?

I have to use the command digitalWrite only 2 times max

Sounds like an assignment designed to help you learn to solve open ended problems. How will feeding you the answer help with that?

sara1305:
Please respond asap.

This is really rude

KASSIMSAMJI:
This is really rude

Agree. As bad as "Urgent".

You seem to have a scope issue.

"I need help" or similar are also pretty silly, though I am inclined to recommend a different sort of forum or service when I see it. :astonished: