Lecture 2 - Button read
Lesing av trykknapp og skriving til LED. Header-filar og eksterne bibliotek. typedef og struct. Introduksjon til peikerar. Deklarasjon og definisjon av funksjonar, parameter og returtype.
Some important C++ concepts
Function definitions
pass
Parameter and return types
pass
Pointers
pass
GPIO and registers
Getting more familiar with registers and reading datasheet.
Exercise: User button - LED control
- Look at the reference manual which port the user LEDs are connected.
- Start a new STM32CubeMX project. If you select the default mode, the LED assignments will be already done.
- Skip clock configurations (for now).
- Do the necessary changes in the Project Manager tab and generate the source code.
- Create a platformio.ini and Copy the necessary content in it.
- Open the project using PlatformIO home page.
- Do these necessary changes after
/*USER CODE BEGIN 3*/
in main.c./* USER CODE BEGIN 3 */ if(HAL_GPIO_ReadPin(USER_Btn_GPIO_Port, USER_Btn_Pin)){ HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET); } else{ HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET); }
- Build and upload.
- Observe the blue LED state as you press user button (blue button) on your board.