cancel
Showing results for 
Search instead for 
Did you mean: 

Question about the LED of STM32F407

Cl.1
Associate II

This is my code.

GPIO_PinState boButton_state ;

printf (" Hello �?� Cruel �?� World \n"); 

while (1)

{

boButton_state = HAL_GPIO_ReadPin ( B1_GPIO_Port , B1_Pin ); 

HAL_GPIO_WritePin ( LD6_GPIO_Port , LD6_Pin , boButton_state );

HAL_GPIO_TogglePin ( LD3_GPIO_Port , LD3_Pin );

HAL_Delay ( TENTH_SEC );

In the code show that the LED(LD3) will toggle every 10th of a second as an indication that the code is running.

At the same moment the LED(LD6) will turn on when i pushbutton User(B1).

Now i need to write the explain about this situation, can i explain will the HAL code inverts the logic so the LED(LD6) normally is off and only will turn on when i push the button?

Thanks in advance.

3 REPLIES 3
TDK
Guru

Yes, HAL_GPIO_TogglePin will toggle LD3 and LD6 will reflect the state of B1.

If you feel a post has answered your question, please click "Accept as Solution".

Thing to remember is that buttons often have a pull-up and ground to zero when pressed. LEDs too can be wired either way, to VCC via a resistor or too GND via a resistor. When the former is used in Open-Drain mode, setting the pin LOW turns ON the LED

Trying using ! to reverse the state if you want other way around

HAL_GPIO_WritePin ( LD6_GPIO_Port , LD6_Pin , !boButton_state );

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Cl.1
Associate II

Awesome! Learned! Thank you!