#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stm32l0xx_hal.h>
#define button GPIO_PIN_1
#define led GPIO_PIN_0
int main(void){
HAL_Init();
__HAL_RCC_GPIOA_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = button;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA,&GPIO_InitStruct);
GPIO_InitStruct.Pin = led;
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);
while(1){
if(!HAL_GPIO_ReadPin(GPIOA,button)){
HAL_GPIO_WritePin(GPIOA,led,GPIO_PIN_RESET);
}
else{
HAL_GPIO_WritePin(GPIOA,led,GPIO_PIN_SET);
}
}
}Loading
st-nucleo-l031k6
st-nucleo-l031k6