#include "stm32c0xx_hal.h"
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
while (1)
{
/* Check Button1 */
if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0) == GPIO_PIN_SET) // Button1 pressed?
{
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_11); // Blink LED1
HAL_Delay(3000);
}
/* Check Button2 */
if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_1) == GPIO_PIN_SET) // Button2 pressed?
{
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_11); // Blink LED2
HAL_Delay(3000);
}
/* If no button pressed → do nothing */
}
}
static void MX_GPIO_Init(void)
{
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* ========== LED PINS ========== */
GPIO_InitStruct.Pin = GPIO_PIN_11;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); // LED1 (PB11)
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); // LED2 (PA11)
/* ========== BUTTON PINS ========== */
GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1; // Button1 + Button2
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLDOWN; // Buttons pull-down
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
}