Basic blink program stm32

Hello,
I have modified blink example as below. Using STM32 blue bill with ST link.

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(10000);                       // wait for a second
}

My expectation is - LED should be on for 1 sec and should be off for 10 seconds? Is my understanding not right?

I see the opposite behaviour. - led on 10sec, off for 1 sec. can I ask why?

It's all a matter of how the LED is wired. If the LED were connected between the LED_BUILTIN pin and ground, then your expectation would be correct. However, in this case the LED is connected between LED_BUILTIN and Vcc, so when the pin is set LOW the LED turns on.

Don't make the mistake of thinking HIGH always means "on". HIGH and LOW are just arbitrary states. You might find your code is easier to understand and maintain if you do something like this:

const byte LEDOnState = LOW;
const byte LEDOffState = HIGH;

void loop() {
  digitalWrite(LED_BUILTIN, LEDOnState);   // turn the LED on
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LEDOffState);    // turn the LED off
  delay(10000);                       // wait for a second
}

I am so sorry, what is that answer, like cheating? just swapping ? not good

void loop() {
  digitalWrite(LED_BUILTIN, LOW);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, HIGH);    // turn the LED off by making the voltage LOW
  delay(10000);                       // wait for a second
}

I am using the STM32 blue pill's built in LED on PC13. I dont know if -" LED is connected between LED_BUILTIN and Vcc, ", but would like to how to confirm this.

The schematic should show this. If that is not good enough then a DVM or multimeter could be used.

vaj4088:
The schematic should show this. If that is not good enough then a DVM or multimeter could be used.

Ok. I am looking for someone who can answer, why - digitalWrite(LED_BUILTIN, LOW); is turning on the LED ?

I thought that pert already answered "why".

vaj4088:
I thought that pert already answered "why".

I read the replies. An answer with "if" is not definite and your to look at "schematic" is only a suggestion.

In case of STM32 blue pill, - Is LED connected between LED_BUILTIN/PC13 and Vcc,?

Yes. From the schematic:
Clipboard01.png

krisferrari:
I am so sorry, what is that answer, like cheating? just swapping ? not good

How is making an LED active LOW cheating? I can see you're still stuck on this HIGH == on thing. That's going to be detrimental to your progress in learning electronics if you can't get past it. Many circuits are active LOW.

krisferrari:
I am using the STM32 blue pill's built in LED on PC13. I dont know if -" LED is connected between LED_BUILTIN and Vcc, ", but would like to how to confirm this.

You already did confirm it with your sketch. You just don't seem to be willing to believe the results of your experiment.

Clipboard01.png