GPIO INPUT -> PULL-UP / PULL-DOWN 설정 가능 (*Floating 방지)GPIO OUTPUT -> PUSH PULL / OPEN DRAIN 설정 가능 OPEN DRAIN : (*외부 소스를 이용하여 OUTPUT을 CONTROL 하고 싶을때 사용)
In STM32, the while(1) loop ensures continuous execution of the code, allowing the microcontroller to repeatedly perform tasks or check conditions indefinitely until reset or power-off.
Reads the button state while preventing switch bounce, updating the button status only when a state change (press or release) is detected, with a debounce delay of 60ms.
void led_left_on(void) // 7 6 5 4 3 2 1 0 @ LED 순차적으로, 200ms 주기로 동작 시키는 함수
{
static int i = 0;
if(i < 8)
{
HAL_GPIO_WritePin(GPIOB, 0xff, 0);
HAL_GPIO_WritePin(GPIOB, 0x01 << i, 1);
HAL_Delay(100);
}
i++;
if(i >= 8)
{
i = 0;
HAL_GPIO_WritePin(GPIOB, 0xff, 0);
HAL_Delay(100);
}
}
void led_right_on(void)
{
for(int i = 0; i < 8 ; i--)
{
HAL_GPIO_WritePin(GPIOB, 0x01 << i, 1);
HAL_Delay(200);
HAL_GPIO_WritePin(GPIOB, 0xff, 0);
}
}
Sequentially controls 8 LEDs on GPIOB with a 100ms delay, turning them on one by one from the least significant to the most significant bit, and resets after all LEDs have been lit. Each mode can be selected by get_button().
6. Testing and Debugging
* Testing Tools: STM32 CUBE IDE, NUCLEO-F411RE
7. References
Include any relevant resources or links used for learning.