![](/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
main.cpp@2:1b6162cd96d4, 2018-04-05 (annotated)
- Committer:
- carter7778
- Date:
- Thu Apr 05 22:42:33 2018 +0000
- Revision:
- 2:1b6162cd96d4
- Parent:
- 0:267836e77e0c
lcd will print which button on direction pad is pressed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
carter7778 | 2:1b6162cd96d4 | 1 | |
bcostm | 0:267836e77e0c | 2 | #include "mbed.h" |
carter7778 | 2:1b6162cd96d4 | 3 | #include "LCD_DISCO_L476VG.h" |
carter7778 | 2:1b6162cd96d4 | 4 | LCD_DISCO_L476VG lcd; |
bcostm | 0:267836e77e0c | 5 | #define USE_PRINTF (1) |
carter7778 | 2:1b6162cd96d4 | 6 | uint8_t title_CENTER[]= " CENTER"; |
carter7778 | 2:1b6162cd96d4 | 7 | uint8_t title_LEFT[]= " LEFT"; |
carter7778 | 2:1b6162cd96d4 | 8 | uint8_t title_RIGHT[]= " RIGHT"; |
carter7778 | 2:1b6162cd96d4 | 9 | uint8_t title_UP[]= " UP"; |
carter7778 | 2:1b6162cd96d4 | 10 | uint8_t title_DOWN[]= " DOWN"; |
carter7778 | 2:1b6162cd96d4 | 11 | |
bcostm | 0:267836e77e0c | 12 | // Joystick button |
bcostm | 0:267836e77e0c | 13 | InterruptIn center(JOYSTICK_CENTER); |
bcostm | 0:267836e77e0c | 14 | InterruptIn left(JOYSTICK_LEFT); |
bcostm | 0:267836e77e0c | 15 | InterruptIn right(JOYSTICK_RIGHT); |
bcostm | 0:267836e77e0c | 16 | InterruptIn up(JOYSTICK_UP); |
bcostm | 0:267836e77e0c | 17 | InterruptIn down(JOYSTICK_DOWN); |
bcostm | 0:267836e77e0c | 18 | // LEDs |
bcostm | 0:267836e77e0c | 19 | DigitalOut led_green(LED1); |
bcostm | 0:267836e77e0c | 20 | DigitalOut led_red(LED2); |
bcostm | 0:267836e77e0c | 21 | void center_released() { |
carter7778 | 2:1b6162cd96d4 | 22 | led_green = 1; |
bcostm | 0:267836e77e0c | 23 | #if USE_PRINTF == 1 |
bcostm | 0:267836e77e0c | 24 | printf("center button released\n"); |
carter7778 | 2:1b6162cd96d4 | 25 | #endif |
bcostm | 0:267836e77e0c | 26 | } |
bcostm | 0:267836e77e0c | 27 | void center_pressed() { |
carter7778 | 2:1b6162cd96d4 | 28 | led_green = 0; |
carter7778 | 2:1b6162cd96d4 | 29 | #if USE_PRINTF == 1 |
carter7778 | 2:1b6162cd96d4 | 30 | printf("center button pressed\n"); |
carter7778 | 2:1b6162cd96d4 | 31 | |
carter7778 | 2:1b6162cd96d4 | 32 | lcd.Clear(); |
carter7778 | 2:1b6162cd96d4 | 33 | lcd. ScrollSentence(title_CENTER, 1,200); |
carter7778 | 2:1b6162cd96d4 | 34 | lcd.Clear(); |
carter7778 | 2:1b6162cd96d4 | 35 | |
carter7778 | 2:1b6162cd96d4 | 36 | |
carter7778 | 2:1b6162cd96d4 | 37 | #endif |
carter7778 | 2:1b6162cd96d4 | 38 | } |
carter7778 | 2:1b6162cd96d4 | 39 | void left_released() { |
bcostm | 0:267836e77e0c | 40 | led_green = 1; |
bcostm | 0:267836e77e0c | 41 | #if USE_PRINTF == 1 |
bcostm | 0:267836e77e0c | 42 | printf("left button released\n"); |
carter7778 | 2:1b6162cd96d4 | 43 | #endif |
bcostm | 0:267836e77e0c | 44 | } |
bcostm | 0:267836e77e0c | 45 | void left_pressed() { |
bcostm | 0:267836e77e0c | 46 | led_green = 1; |
carter7778 | 2:1b6162cd96d4 | 47 | #if USE_PRINTF == 1 |
bcostm | 0:267836e77e0c | 48 | printf("left button pressed\n"); |
carter7778 | 2:1b6162cd96d4 | 49 | |
carter7778 | 2:1b6162cd96d4 | 50 | lcd.Clear(); |
carter7778 | 2:1b6162cd96d4 | 51 | lcd. ScrollSentence(title_LEFT, 1,200); |
carter7778 | 2:1b6162cd96d4 | 52 | lcd.Clear(); |
carter7778 | 2:1b6162cd96d4 | 53 | #endif |
bcostm | 0:267836e77e0c | 54 | } |
bcostm | 0:267836e77e0c | 55 | void right_released() { |
carter7778 | 2:1b6162cd96d4 | 56 | led_green = 1; |
bcostm | 0:267836e77e0c | 57 | #if USE_PRINTF == 1 |
bcostm | 0:267836e77e0c | 58 | printf("right button released\n"); |
carter7778 | 2:1b6162cd96d4 | 59 | #endif |
bcostm | 0:267836e77e0c | 60 | } |
bcostm | 0:267836e77e0c | 61 | void right_pressed() { |
bcostm | 0:267836e77e0c | 62 | led_green = 1; |
carter7778 | 2:1b6162cd96d4 | 63 | #if USE_PRINTF == 1 |
bcostm | 0:267836e77e0c | 64 | printf("right button pressed\n"); |
carter7778 | 2:1b6162cd96d4 | 65 | lcd.Clear(); |
carter7778 | 2:1b6162cd96d4 | 66 | lcd. ScrollSentence(title_RIGHT, 1,200); |
carter7778 | 2:1b6162cd96d4 | 67 | lcd.Clear(); |
carter7778 | 2:1b6162cd96d4 | 68 | #endif |
bcostm | 0:267836e77e0c | 69 | } |
bcostm | 0:267836e77e0c | 70 | void up_released() { |
bcostm | 0:267836e77e0c | 71 | led_green = 0; |
bcostm | 0:267836e77e0c | 72 | #if USE_PRINTF == 1 |
bcostm | 0:267836e77e0c | 73 | printf("up button released\n"); |
carter7778 | 2:1b6162cd96d4 | 74 | #endif |
bcostm | 0:267836e77e0c | 75 | } |
bcostm | 0:267836e77e0c | 76 | void up_pressed() { |
bcostm | 0:267836e77e0c | 77 | led_green = 1; |
carter7778 | 2:1b6162cd96d4 | 78 | #if USE_PRINTF == 1 |
bcostm | 0:267836e77e0c | 79 | printf("up button pressed\n"); |
carter7778 | 2:1b6162cd96d4 | 80 | lcd.Clear(); |
carter7778 | 2:1b6162cd96d4 | 81 | lcd. ScrollSentence(title_UP, 1,200); |
carter7778 | 2:1b6162cd96d4 | 82 | lcd.Clear(); |
carter7778 | 2:1b6162cd96d4 | 83 | #endif |
bcostm | 0:267836e77e0c | 84 | } |
bcostm | 0:267836e77e0c | 85 | void down_released() { |
carter7778 | 2:1b6162cd96d4 | 86 | led_green = 1; |
bcostm | 0:267836e77e0c | 87 | #if USE_PRINTF == 1 |
bcostm | 0:267836e77e0c | 88 | printf("down button released\n"); |
carter7778 | 2:1b6162cd96d4 | 89 | #endif |
bcostm | 0:267836e77e0c | 90 | } |
bcostm | 0:267836e77e0c | 91 | void down_pressed() { |
bcostm | 0:267836e77e0c | 92 | led_green = 1; |
carter7778 | 2:1b6162cd96d4 | 93 | #if USE_PRINTF == 1 |
bcostm | 0:267836e77e0c | 94 | printf("down button pressed\n"); |
carter7778 | 2:1b6162cd96d4 | 95 | lcd.Clear(); |
carter7778 | 2:1b6162cd96d4 | 96 | lcd. ScrollSentence(title_DOWN, 1,200); |
carter7778 | 2:1b6162cd96d4 | 97 | lcd.Clear(); |
carter7778 | 2:1b6162cd96d4 | 98 | #endif |
bcostm | 0:267836e77e0c | 99 | } |
bcostm | 0:267836e77e0c | 100 | int main() { |
carter7778 | 2:1b6162cd96d4 | 101 | #if USE_PRINTF == 1 |
bcostm | 0:267836e77e0c | 102 | int i = 0; |
bcostm | 0:267836e77e0c | 103 | printf("\nStart!\n"); |
bcostm | 0:267836e77e0c | 104 | #endif |
carter7778 | 2:1b6162cd96d4 | 105 | |
bcostm | 0:267836e77e0c | 106 | // Both rise and fall edges generate an interrupt |
bcostm | 0:267836e77e0c | 107 | center.fall(¢er_released); |
bcostm | 0:267836e77e0c | 108 | center.rise(¢er_pressed); |
bcostm | 0:267836e77e0c | 109 | left.fall(&left_released); |
bcostm | 0:267836e77e0c | 110 | left.rise(&left_pressed); |
bcostm | 0:267836e77e0c | 111 | right.fall(&right_released); |
bcostm | 0:267836e77e0c | 112 | right.rise(&right_pressed); |
bcostm | 0:267836e77e0c | 113 | up.fall(&up_released); |
bcostm | 0:267836e77e0c | 114 | up.rise(&up_pressed); |
bcostm | 0:267836e77e0c | 115 | down.fall(&down_released); |
bcostm | 0:267836e77e0c | 116 | down.rise(&down_pressed); |
bcostm | 0:267836e77e0c | 117 | // Add pull-down on these pins |
bcostm | 0:267836e77e0c | 118 | // Warning: must be done AFTER edges setting |
bcostm | 0:267836e77e0c | 119 | left.mode(PullDown); |
bcostm | 0:267836e77e0c | 120 | right.mode(PullDown); |
bcostm | 0:267836e77e0c | 121 | up.mode(PullDown); |
bcostm | 0:267836e77e0c | 122 | down.mode(PullDown); |
carter7778 | 2:1b6162cd96d4 | 123 | |
bcostm | 0:267836e77e0c | 124 | while (1) { |
bcostm | 0:267836e77e0c | 125 | led_red = !led_red; |
bcostm | 0:267836e77e0c | 126 | wait(1.0); |
carter7778 | 2:1b6162cd96d4 | 127 | #if USE_PRINTF == 1 |
bcostm | 0:267836e77e0c | 128 | printf("main %d\n", i++); |
carter7778 | 2:1b6162cd96d4 | 129 | #endif |
bcostm | 0:267836e77e0c | 130 | } |
bcostm | 0:267836e77e0c | 131 | } |
carter7778 | 2:1b6162cd96d4 | 132 |