Update of the GlassLCD example that uses on the on board LCD of the Discovery STM32L476 board to display what button is being pressed on the joystick.
Dependencies: BSP_DISCO_L476VG LCD_DISCO_L476VG mbed
Fork of DISCO_L476VG_GlassLCD by
Revision 5:c15ad9683195, committed 2018-06-15
- Comitter:
- jblackann
- Date:
- Fri Jun 15 12:51:21 2018 +0000
- Parent:
- 4:19430589f400
- Commit message:
- An update of the GlassLCD project for the Discovery STM32L476 board to display on the LCD what buttons are being pressed.
Changed in this revision
BSP_DISCO_L476VG.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 19430589f400 -r c15ad9683195 BSP_DISCO_L476VG.lib --- a/BSP_DISCO_L476VG.lib Thu Jul 06 09:10:51 2017 +0000 +++ b/BSP_DISCO_L476VG.lib Fri Jun 15 12:51:21 2018 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/ST/code/BSP_DISCO_L476VG/#23fea64454eb +https://developer.mbed.org/teams/ST/code/BSP_DISCO_L476VG/#472232f07925
diff -r 19430589f400 -r c15ad9683195 main.cpp --- a/main.cpp Thu Jul 06 09:10:51 2017 +0000 +++ b/main.cpp Fri Jun 15 12:51:21 2018 +0000 @@ -3,22 +3,138 @@ LCD_DISCO_L476VG lcd; +#define USE_PRINTF (1) + +// Joystick button +InterruptIn center(JOYSTICK_CENTER); +InterruptIn left(JOYSTICK_LEFT); +InterruptIn right(JOYSTICK_RIGHT); +InterruptIn up(JOYSTICK_UP); +InterruptIn down(JOYSTICK_DOWN); + +// LEDs DigitalOut led_green(LED1); +DigitalOut led_red(LED2); + +void center_released() { + led_green = 0; + lcd.Clear(); +#if USE_PRINTF == 1 + printf("center button released\n"); +#endif +} + +void center_pressed() { + led_green = 1; + lcd.DisplayString((uint8_t *)"Center"); +#if USE_PRINTF == 1 + printf("center button pressed\n"); +#endif +} + +void left_released() { + led_green = 0; + lcd.Clear(); +#if USE_PRINTF == 1 + printf("left button released\n"); +#endif +} + +void left_pressed() { + led_green = 1; + lcd.DisplayString((uint8_t *)"Left"); +#if USE_PRINTF == 1 + printf("left button pressed\n"); +#endif +} + +void right_released() { + led_green = 0; + lcd.Clear(); +#if USE_PRINTF == 1 + printf("right button released\n"); +#endif +} + +void right_pressed() { + led_green = 1; + lcd.DisplayString((uint8_t *)"Right"); +#if USE_PRINTF == 1 + printf("right button pressed\n"); +#endif +} + +void up_released() { + led_green = 0; + lcd.Clear(); +#if USE_PRINTF == 1 + printf("up button released\n"); +#endif +} + +void up_pressed() { + led_green = 1; + lcd.DisplayString((uint8_t *)"Up"); +#if USE_PRINTF == 1 + printf("up button pressed\n"); +#endif +} + +void down_released() { + led_green = 0; + lcd.Clear(); +#if USE_PRINTF == 1 + printf("down button released\n"); +#endif +} + +void down_pressed() { + led_green = 1; + lcd.DisplayString((uint8_t *)"Down"); +#if USE_PRINTF == 1 + printf("down button pressed\n"); +#endif +} int main() { uint32_t temp = 0; uint8_t stemp[7] = {0}; - uint8_t title[] = " DISCOVERY STM32L476"; + //uint8_t title[] = " DISCOVERY STM32L476"; + uint8_t title[] = " EET Micros 1"; + #if USE_PRINTF == 1 + int i = 0; + printf("\nStart!\n"); +#endif + + // Both rise and fall edges generate an interrupt + center.fall(¢er_released); + center.rise(¢er_pressed); + left.fall(&left_released); + left.rise(&left_pressed); + right.fall(&right_released); + right.rise(&right_pressed); + up.fall(&up_released); + up.rise(&up_pressed); + down.fall(&down_released); + down.rise(&down_pressed); + + // Add pull-down on these pins + // Warning: must be done AFTER edges setting + left.mode(PullDown); + right.mode(PullDown); + up.mode(PullDown); + down.mode(PullDown); printf("Hello\n"); led_green = 1; lcd.Clear(); - lcd.DisplayString((uint8_t *)"HELLO"); + lcd.DisplayString((uint8_t *)"YSU"); wait(1); printf("Scroll sequence\n"); led_green = 0; + led_red = 1; lcd.Clear(); lcd.ScrollSentence(title, 2, 200); lcd.Clear(); @@ -31,6 +147,7 @@ temp++; if (temp > 4) temp = 0; led_green = !led_green; + led_red = !led_red; wait(1); } }