2020-04-06 03:05 AM
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.
2020-04-06 06:30 AM
Yes, HAL_GPIO_TogglePin will toggle LD3 and LD6 will reflect the state of B1.
2020-04-06 08:24 AM
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 );
2020-04-06 07:01 PM
Awesome! Learned! Thank you!