Troubleshoot Sketch

I am trying to make a schematic and sketch to demonstrate a LED without the delay() function. Under the Arduino IDE 0.1Basics menu is a simple blink sketch. It uses the delay() function. I assume it is included for fast test of connections for upload of a sketch to a board, since the built-in LED blinks with power connection -but not if the port is wrong- as an example of what a user might want to test.
Under the 0.2Digital menu is a BlinkWithoutDelay sketch. It is in the comments of this sketch that can be found the suggestion to try another function while blinking LED. It is line 44, as follows:

// here is where you'd put code that needs to be running all the time.

So, yours truly decided to try it. I am not trained in writing code. I proceed by reverse-engineering existing code for my needs, in other words, like a hacker. Some modifications are easy, such as changing the duration of a blink, or the color of a RGB LED. It was easy to modify the 0.1Basic blink sketch to not blink, but remain lighted steadily, thus removing the need for delay(). This is my edited version:

// initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)

}

If you look at the 0.1Basic Blink sketch, you will see what was omitted. I then copied these lines of code -without the delay() function- over to the 0.2Digital, BlinkWithoutDelay LED sketch. My intention being to make one LED remain lit while a second LED blinks, however, it is not working. The steady LED works, but not the blinker, LED number two. Copied below is my entire sketch. Most comments in the source code have been omitted for brevity. I verified this sketch before upload, and received no errors then, or after upload. The pins look right, as specified, both working LEDs, with correct polarity.

// light two LEDs, one steady, one blinks

const int led_A_Pin = 12;
const int led_B_Pin = 11;
int ledState = LOW;
unsigned long previousMillis = 0;
const long interval = 1000;

void setup() {

  pinMode(led_A_Pin, OUTPUT);
  pinMode(led_B_Pin, OUTPUT);
}

void loop() {
  digitalWrite(led_A_Pin, HIGH);
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;

    if (led_B_Pin == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;
    }

    digitalWrite(led_B_Pin, ledState);
  }
}

You hacked it a little too much. First you define led_B_Pin:

brianeo:

const int led_B_Pin = 11;

Then you check if the value of led_B_Pin is equal to LOW:

brianeo:

    if (led_B_Pin == LOW) {

LOW happens to be defined as 0 so that statement is the equivalent of:

    if (11 == 0) {

so that will never be true and the code inside that if block will never run.

Compare your code to the unmodified BlinkWithoutDelay sketch to see if you can figure out how to fix it.

One other thing:

brianeo:

void loop() {

digitalWrite(LED_BUILTIN, HIGH);  // turn the LED on (HIGH is the voltage level)

}

There's no need to write the same value to the pin over and over again in the loop. Since it will never change you can just set the state in setup(), which only runs once. It takes a little time for the microcontroller to run that code and you always want to keep your loop() running as fast as possible. It won't cause a problem in this case but it's a bad habit to get into. You have the same wasteful code in your second sketch.

Thanks for your reply. You are right about hacking too fast. Even a hacker needs to know what he's doing. After posting my question, I noticed another sketch somewhere that includes currentMillis before something about if...previousMillis. My guess is that would help my sketch. If the sketch sets a time for two different LEDs, they both need to refer to a base time. For example, LED 1 blinks 300 millis after 0 time, and LED 2 blinks 600 millis after 0. Is that the right idea? That is, in addition to needing to fix the existing code errors in my combined sketch. I went back to the built-in tutorials afterwards. That's the problem with reading the questions posted by experienced hackers. It leads to over-reaching.

Get your current code working and then have a try at making the LEDs blink at different speeds.