Arduino Looping states in Void Loop help needed for a novice.

See reply #18

more or less this is in a doubled sense (almost) fully functional description.
still missing some parts. What would be so hard to follow the instructions in post #18??

As a consequence of not following the instructions I will bomb you with a lot of new information. Let's see if you can cope with that:

As you have only two states it is still doable with if-conditions.
and it can be done like Bob suggested with writing it as pseudo code.

For functionalities that have more than two "states" a switch-case statement is more suitable.

Depending on the value of your variable "count" the next button-press switches from state 1 (= blinking LED on IO-pin 2 to state 2 (blinking LED on io-Pin 7)
or vice versa.

You should divide programs into small functions where each function does one thing.

there is a function "blink LED 1"
and
a function "blink LED 2"

blinking can be done by inverting the current state of the IO-pin

There is another command similar to digitalWrite.
digitalRead.

Even if an IO-pin is configured as output you still can read the state of the IO-pin.

some example-codes that show how digitalRead can be used for blinking
simply blinking LED 2:

void loop() {
  digitalWrite(Pin2,HIGH);
  delay(400);

  digitalWrite(Pin2,LOW);
  delay(400);
}

making the actual state of the IO-pin visible in the serial monitor

void loop() {
  digitalWrite(Pin2,HIGH);

  if (digitalRead(Pin2) == HIGH) {
    Serial.println("Pin2 is HIGH");
  }
  delay(400);

  digitalWrite(Pin2,LOW);
  if (digitalRead(Pin2) == LOW) {
    Serial.println("Pin2 is HIGH");
  }
  delay(400);
}

using digitalRead to get the actual state of the IO-pin

void loop() {
  byte IO_PinState = digitalRead(Pin2);

  if (IO_PinState == LOW) {
    digitalWrite(Pin2,HIGH); // set to opposite state 
  }  

  if (IO_PinState == HIGH) {
    digitalWrite(Pin2,LOW); // set to opposite state 
  }  

  delay(400);
}

This can be done even shorter with the not-operator "!"
! HIGH results in LOW
! LOW results in HIGH

Do you see the not-operator ?! The attention-mark "!"

which combines the digitalRead with the digitalWrite

void loop() {
    digitalWrite(Pin2, !digitalRead(Pin2) ); // set to opposite state by using the not-operator
    delay(400);
}    

digitalWrite (first parameter , second parameter )

first parameter like always "Pin2"

second parameter result of !digitalRead(Pin2)

digitalRead(Pin2) // if the IO-pin is set to state HIGH the result of "digitalRead is HIGH

digitalRead(Pin2) // if the IO-pin is set to state LOW the result of "digitalRead is LOW

The not-operator inverts this result

!HIGH results in LOW

!LOW results in HIGH

so the IO-pin gets switched always to the opposite state LOW-HIGH-LOW-HIGH-LOW-HIGH = blinking

This could be packed into a function
for LED on IO-pin 2

void Blink_LED_A() {
  digitalWrite(Pin2, !digitalRead(Pin2) ); // set to opposite state by using the not-operator
  delay(400);
}

for LED on IO-pin 7

void Blink_LED_B() {
  digitalWrite(Pin7, !digitalRead(Pin7) ); // set to opposite state by using the not-operator
  delay(400);
}

and then the functions were called inside loop

void loop() {
  Blink_LED_A() 
  Blink_LED_B() 
}

This is already pretty much new stuff.
So try it and report results whatever the results will be.

always post your whole code as a code-section to make everything clear

best regards Stefan

I am still very new. Sorry but I don't understand the example?

unsufficient answer: there are about 10 examples in this thread
quote the example you don't understand and post the code of the example you don't understand as a code-section

Do you know how to increment a count every time a button becomes pressed ?

Do you know how to test the value of a variable and run different code based on its value ?

why does changing the LEDs, not which pattern, depend on the button state?