Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.c
- Revision:
- 3:858ea360dbbe
- Parent:
- 2:8c4e755038ce
- Child:
- 5:9956a807573a
--- a/main.c Fri Feb 24 22:46:53 2017 +0000 +++ b/main.c Fri Feb 24 22:57:52 2017 +0000 @@ -15,8 +15,11 @@ LED4_GPIO_CLK_ENABLE(); LED5_GPIO_CLK_ENABLE(); + UP_JOY_GPIO_CLK_ENABLE(); + DOWN_JOY_GPIO_CLK_ENABLE(); GPIO_InitTypeDef gpio; + gpio.Mode = GPIO_MODE_OUTPUT_PP; gpio.Pull = GPIO_NOPULL; gpio.Speed = GPIO_SPEED_FREQ_LOW; @@ -26,10 +29,30 @@ gpio.Pin = LED5_PIN; HAL_GPIO_Init(LED5_GPIO_PORT, &gpio); + + gpio.Mode = GPIO_MODE_INPUT; + gpio.Pull = GPIO_PULLDOWN; + gpio.Pin = UP_JOY_PIN; + HAL_GPIO_Init(UP_JOY_GPIO_PORT, &gpio); + + gpio.Pin = DOWN_JOY_PIN; + HAL_GPIO_Init(DOWN_JOY_GPIO_PORT, &gpio); + + HAL_GPIO_TogglePin(LED5_GPIO_PORT, LED5_PIN); + HAL_Delay(300); + HAL_GPIO_TogglePin(LED4_GPIO_PORT, LED4_PIN); + HAL_Delay(300); + HAL_GPIO_TogglePin(LED5_GPIO_PORT, LED5_PIN); + HAL_Delay(300); + HAL_GPIO_TogglePin(LED4_GPIO_PORT, LED4_PIN); + HAL_Delay(300); + while (1) { - HAL_GPIO_TogglePin(LED5_GPIO_PORT, LED5_PIN); - HAL_Delay(300); - HAL_GPIO_TogglePin(LED4_GPIO_PORT, LED4_PIN); + GPIO_PinState state = HAL_GPIO_ReadPin(UP_JOY_GPIO_PORT,UP_JOY_PIN); + HAL_GPIO_WritePin(LED4_GPIO_PORT, LED4_PIN, state); + + state = HAL_GPIO_ReadPin(DOWN_JOY_GPIO_PORT,DOWN_JOY_PIN); + HAL_GPIO_WritePin(LED5_GPIO_PORT, LED5_PIN, state); } }