*Code:*
if(HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13) == GPIO_PIN_RESET) // Checking if button state is not pressed
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET); // If button not pressed, turn off LED else
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET); // else turn on LED
*Detailed explanation of Push button example:*
[ Ссылка ]
*Learn STM32 Controllers Programming*
[ Ссылка ]
Ещё видео!