#include "main.h"
/* Variables globales si besoin */
// ...
int main(void)
{
/* Initialisation HAL et système */
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
/* USER CODE BEGIN 2 */
// Ici tu peux mettre du code d’initialisation si nécessaire
/* USER CODE END 2 */
/* USER CODE BEGIN 3 */
while (1)
{
// Lire l’état du bouton (PC13)
if (HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13) == GPIO_PIN_RESET)
{
// Bouton appuyé → LED ON
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
}
else
{
// Bouton relâché → LED OFF
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);
}
}
/* USER CODE END 3 */
}
/* --- Fonctions générées automatiquement par CubeIDE --- */
void SystemClock_Config(void)
{
// Configuration d’horloge générée par CubeIDE
}
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* Activer les horloges GPIO */
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
/* Configurer PA5 en sortie (LED) */
GPIO_InitStruct.Pin = GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* Configurer PC13 en entrée (Bouton) avec Pull-up */
GPIO_InitStruct.Pin = GPIO_PIN_13;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
}