![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
EET 3735 Rachid, Tyler, Ryan
Dependencies: BSP_DISCO_L476VG LCD_DISCO_L476VG mbed
Fork of DISCO_L476VG_leds_buttons by
Diff: main.cpp
- Revision:
- 2:1b6162cd96d4
- Parent:
- 0:267836e77e0c
--- a/main.cpp Tue Jun 06 14:41:33 2017 +0200 +++ b/main.cpp Thu Apr 05 22:42:33 2018 +0000 @@ -1,95 +1,108 @@ + #include "mbed.h" - +#include "LCD_DISCO_L476VG.h" +LCD_DISCO_L476VG lcd; #define USE_PRINTF (1) - + uint8_t title_CENTER[]= " CENTER"; + uint8_t title_LEFT[]= " LEFT"; + uint8_t title_RIGHT[]= " RIGHT"; + uint8_t title_UP[]= " UP"; + uint8_t title_DOWN[]= " DOWN"; + // 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; + led_green = 1; #if USE_PRINTF == 1 printf("center button released\n"); -#endif +#endif } - void center_pressed() { + led_green = 0; +#if USE_PRINTF == 1 + printf("center button pressed\n"); + + lcd.Clear(); + lcd. ScrollSentence(title_CENTER, 1,200); + lcd.Clear(); + + +#endif +} +void left_released() { led_green = 1; -#if USE_PRINTF == 1 - printf("center button pressed\n"); -#endif -} - -void left_released() { - led_green = 0; #if USE_PRINTF == 1 printf("left button released\n"); -#endif +#endif } - void left_pressed() { led_green = 1; -#if USE_PRINTF == 1 +#if USE_PRINTF == 1 printf("left button pressed\n"); -#endif + + lcd.Clear(); + lcd. ScrollSentence(title_LEFT, 1,200); + lcd.Clear(); +#endif } - void right_released() { - led_green = 0; + led_green = 1; #if USE_PRINTF == 1 printf("right button released\n"); -#endif +#endif } - void right_pressed() { led_green = 1; -#if USE_PRINTF == 1 +#if USE_PRINTF == 1 printf("right button pressed\n"); -#endif + lcd.Clear(); + lcd. ScrollSentence(title_RIGHT, 1,200); + lcd.Clear(); +#endif } - void up_released() { led_green = 0; #if USE_PRINTF == 1 printf("up button released\n"); -#endif +#endif } - void up_pressed() { led_green = 1; -#if USE_PRINTF == 1 +#if USE_PRINTF == 1 printf("up button pressed\n"); -#endif + lcd.Clear(); + lcd. ScrollSentence(title_UP, 1,200); + lcd.Clear(); +#endif } - void down_released() { - led_green = 0; + led_green = 1; #if USE_PRINTF == 1 printf("down button released\n"); -#endif +#endif } - void down_pressed() { led_green = 1; -#if USE_PRINTF == 1 +#if USE_PRINTF == 1 printf("down button pressed\n"); -#endif + lcd.Clear(); + lcd. ScrollSentence(title_DOWN, 1,200); + lcd.Clear(); +#endif } - int main() { - -#if USE_PRINTF == 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); @@ -101,19 +114,19 @@ 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); - + while (1) { led_red = !led_red; wait(1.0); -#if USE_PRINTF == 1 +#if USE_PRINTF == 1 printf("main %d\n", i++); -#endif +#endif } } +