#include "stm32c0xx_hal.h"
void SystemClock_Config(void);
int main(void)
{
#define LED1_PIN GPIO_PIN_0
#define LED2_PIN GPIO_PIN_1
#define LED3_PIN GPIO_PIN_4
#define LED4_PIN GPIO_PIN_1
#define LED_PORT1 GPIOA
#define LED_PORT2 GPIOA
#define LED_PORT3 GPIOA
#define LED_PORT4 GPIOB
#define BUTTON_PIN GPIO_PIN_7 //C0
#define BUTTON_PORT GPIOB
void GPIO_Init(void);
void allumerLEDsGaucheADroite(void);
void eteindreLEDsDroiteAGauche(void);
int main(void)
{
HAL_Init();
GPIO_Init();
while (1)
{
if (HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN) == GPIO_PIN_RESET)
{
allumerLEDsGaucheADroite();
}
else
{
eteindreLEDsDroiteAGauche();
}
}
}
void GPIO_INIT(void)
{
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = LED1_PIN | LED2_PIN |LED3_PIN;
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);
GPIO_InitStruct.Pin = LED4_PIN;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_InitStruct.Pin = BUTTON_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
}
void allumerLEDsGaucheADroite(void)
{
HAL_GPIO_WritePin(LED_PORT1, LED1_PIN, GPIO_PIN_SET);
HAL_Delay(200);
HAL_GPIO_WritePin(LED_PORT2, LED2_PIN, GPIO_PIN_SET);
HAL_Delay(200);
HAL_GPIO_WritePin(LED_PORT3, LED3_PIN, GPIO_PIN_SET);
HAL_Delay(200);
HAL_GPIO_WritePin(LED_PORT4, LED4_PIN, GPIO_PIN_SET);
HAL_Delay(200);
}
void eteindreLEDsDroiteAGauche(void)
{ HAL_GPIO_WritePin(LED_PORT4, LED4_PIN, GPIO_PIN_RESET);
HAL_Delay(200);
HAL_GPIO_WritePin(LED_PORT3, LED3_PIN, GPIO_PIN_RESET);
HAL_Delay(200);
HAL_GPIO_WritePin(LED_PORT2, LED2_PIN, GPIO_PIN_RESET);
HAL_Delay(200);
HAL_GPIO_WritePin(LED_PORT1, LED1_PIN, GPIO_PIN_RESET);
HAL_Delay(200);
}
}