![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Sample usage of lightweight C12832 LCD library
Just look at that sample - easy and lightweight text driven interface
main.cpp@2:e3c117a9b81b, 2014-10-07 (annotated)
- Committer:
- medvdv
- Date:
- Tue Oct 07 20:53:45 2014 +0000
- Revision:
- 2:e3c117a9b81b
- Parent:
- 1:58927e4da529
Example of library functions with new menu driven interface
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
medvdv | 0:9b6c469485ea | 1 | // |
medvdv | 0:9b6c469485ea | 2 | // MBED Application Board |
medvdv | 0:9b6c469485ea | 3 | // Lightweight C12832 LCD library |
medvdv | 0:9b6c469485ea | 4 | // 2014, Alexander Medvedev, @medvdv |
medvdv | 0:9b6c469485ea | 5 | // |
medvdv | 0:9b6c469485ea | 6 | |
medvdv | 0:9b6c469485ea | 7 | // |
medvdv | 0:9b6c469485ea | 8 | // Usage Sample |
medvdv | 0:9b6c469485ea | 9 | // |
medvdv | 0:9b6c469485ea | 10 | |
medvdv | 0:9b6c469485ea | 11 | #include "mbed.h" |
medvdv | 0:9b6c469485ea | 12 | |
medvdv | 0:9b6c469485ea | 13 | #include "lcd128lib.h" |
medvdv | 0:9b6c469485ea | 14 | |
medvdv | 2:e3c117a9b81b | 15 | #include "lcd128menu.h" |
medvdv | 0:9b6c469485ea | 16 | |
medvdv | 0:9b6c469485ea | 17 | lcd128 lcd; |
medvdv | 0:9b6c469485ea | 18 | |
medvdv | 2:e3c117a9b81b | 19 | bool menuCheckVariable = false; |
medvdv | 2:e3c117a9b81b | 20 | int menuRadioVariable = 1; |
medvdv | 2:e3c117a9b81b | 21 | float menuProgressBar = 0.5; |
medvdv | 2:e3c117a9b81b | 22 | |
medvdv | 2:e3c117a9b81b | 23 | lcd128entry menuMain[] = { |
medvdv | 0:9b6c469485ea | 24 | |
medvdv | 2:e3c117a9b81b | 25 | { APPMENU_COMMENT, 0, "Main Menu", true, false, 0, 0, 0, NULL }, |
medvdv | 2:e3c117a9b81b | 26 | { APPMENU_ACTION, 1, "Action Item", false, false, 0, 0, 0, NULL }, |
medvdv | 2:e3c117a9b81b | 27 | { APPMENU_ACTION, 2, "Other Action", false, false, 0, 0, 0, NULL }, |
medvdv | 2:e3c117a9b81b | 28 | { APPMENU_BREAK, 0, NULL, false, false, 0, 0, 0, NULL }, |
medvdv | 2:e3c117a9b81b | 29 | { APPMENU_CHECK, 0, "Check Button", false, false, 0, 0, 0, & menuCheckVariable }, |
medvdv | 2:e3c117a9b81b | 30 | { APPMENU_BREAK, 0, NULL, false, false, 0, 0, 0, NULL }, |
medvdv | 2:e3c117a9b81b | 31 | { APPMENU_COMMENT, 0, "Select one:", false, false, 0, 0, 0, NULL }, |
medvdv | 2:e3c117a9b81b | 32 | { APPMENU_RADIO, 1, "Radio Button 1", false, false, 0, 0, 0, & menuRadioVariable }, |
medvdv | 2:e3c117a9b81b | 33 | { APPMENU_RADIO, 2, "Radio Button 2", false, false, 0, 0, 0, & menuRadioVariable }, |
medvdv | 2:e3c117a9b81b | 34 | { APPMENU_RADIO, 3, "Radio Button 3", false, false, 0, 0, 0, & menuRadioVariable }, |
medvdv | 2:e3c117a9b81b | 35 | { APPMENU_BAR, 0, NULL, false, false, 0, 0, 0, & menuProgressBar }, |
medvdv | 0:9b6c469485ea | 36 | |
medvdv | 2:e3c117a9b81b | 37 | }; |
medvdv | 2:e3c117a9b81b | 38 | |
medvdv | 0:9b6c469485ea | 39 | int main() |
medvdv | 0:9b6c469485ea | 40 | { |
medvdv | 2:e3c117a9b81b | 41 | BusIn joy(p15, p12, p13, p16); |
medvdv | 2:e3c117a9b81b | 42 | DigitalIn fire(p14); |
medvdv | 2:e3c117a9b81b | 43 | |
medvdv | 2:e3c117a9b81b | 44 | lcd.Reset(); |
medvdv | 2:e3c117a9b81b | 45 | |
medvdv | 2:e3c117a9b81b | 46 | lcd.XY(0, 0); |
medvdv | 2:e3c117a9b81b | 47 | lcd.Bold(true); lcd.String("LCD LIBRARY"); lcd.Bold(false); |
medvdv | 2:e3c117a9b81b | 48 | lcd.Row(1, "Simple interface library with nice proportional font."); |
medvdv | 2:e3c117a9b81b | 49 | lcd.Row(3, "Push joystick!", true, LCD_ALIGN_CENTER); |
medvdv | 2:e3c117a9b81b | 50 | lcd.InverseRow(2, 0x80); // Add one inverted pixel line upper than last row |
medvdv | 0:9b6c469485ea | 51 | |
medvdv | 2:e3c117a9b81b | 52 | lcd.Update(); |
medvdv | 2:e3c117a9b81b | 53 | |
medvdv | 2:e3c117a9b81b | 54 | wait_ms(500); while(! fire) wait_ms(100); |
medvdv | 1:58927e4da529 | 55 | |
medvdv | 2:e3c117a9b81b | 56 | lcd.Row(0, "Left aligned text"); |
medvdv | 2:e3c117a9b81b | 57 | lcd.Row(1, "Center aligned text", false, LCD_ALIGN_CENTER); |
medvdv | 2:e3c117a9b81b | 58 | lcd.Row(2, "Right aligned text", false, LCD_ALIGN_RIGHT); |
medvdv | 2:e3c117a9b81b | 59 | lcd.InverseRow(2, 0x80); // Add one inverted pixel line upper than last row |
medvdv | 2:e3c117a9b81b | 60 | |
medvdv | 2:e3c117a9b81b | 61 | lcd.Update(); |
medvdv | 2:e3c117a9b81b | 62 | |
medvdv | 2:e3c117a9b81b | 63 | wait_ms(500); while(! fire) wait_ms(100); |
medvdv | 2:e3c117a9b81b | 64 | |
medvdv | 2:e3c117a9b81b | 65 | lcd.Clear(0); lcd.Clear(1); lcd.Clear(2); |
medvdv | 0:9b6c469485ea | 66 | |
medvdv | 2:e3c117a9b81b | 67 | lcd.XY(0, 1); |
medvdv | 2:e3c117a9b81b | 68 | lcd.Bold(true); lcd.String("Bold"); lcd.Bold(false); |
medvdv | 2:e3c117a9b81b | 69 | lcd.String(" and "); |
medvdv | 2:e3c117a9b81b | 70 | lcd.Underline(true); lcd.String("underlined"); lcd.Underline(false); |
medvdv | 2:e3c117a9b81b | 71 | lcd.String(" text"); |
medvdv | 2:e3c117a9b81b | 72 | |
medvdv | 2:e3c117a9b81b | 73 | lcd.InverseRow(2, 0x80); // Add one inverted pixel line upper than last row |
medvdv | 2:e3c117a9b81b | 74 | |
medvdv | 2:e3c117a9b81b | 75 | lcd.Update(); |
medvdv | 2:e3c117a9b81b | 76 | |
medvdv | 2:e3c117a9b81b | 77 | wait_ms(500); while(! fire) wait_ms(100); |
medvdv | 1:58927e4da529 | 78 | |
medvdv | 2:e3c117a9b81b | 79 | lcd.Clear(0); lcd.Clear(1); lcd.Clear(2); lcd.InverseRow(2, 0x80); |
medvdv | 2:e3c117a9b81b | 80 | |
medvdv | 2:e3c117a9b81b | 81 | lcd.Row(0, "Arbitary X position:"); |
medvdv | 2:e3c117a9b81b | 82 | |
medvdv | 2:e3c117a9b81b | 83 | wait_ms(500); |
medvdv | 2:e3c117a9b81b | 84 | |
medvdv | 2:e3c117a9b81b | 85 | int x = 0; |
medvdv | 2:e3c117a9b81b | 86 | |
medvdv | 2:e3c117a9b81b | 87 | do { |
medvdv | 2:e3c117a9b81b | 88 | lcd.Clear(1); |
medvdv | 2:e3c117a9b81b | 89 | lcd.XY(5 + x/8, 1); |
medvdv | 2:e3c117a9b81b | 90 | lcd.Character(LCD_CLOCK0 + (x % 8)); |
medvdv | 2:e3c117a9b81b | 91 | lcd.Update(); |
medvdv | 2:e3c117a9b81b | 92 | x += 1; |
medvdv | 2:e3c117a9b81b | 93 | x %= 113*8; |
medvdv | 2:e3c117a9b81b | 94 | wait_ms(100); |
medvdv | 2:e3c117a9b81b | 95 | } while(! fire); |
medvdv | 2:e3c117a9b81b | 96 | |
medvdv | 2:e3c117a9b81b | 97 | wait_ms(500); |
medvdv | 2:e3c117a9b81b | 98 | |
medvdv | 2:e3c117a9b81b | 99 | lcd.Clear(0); lcd.Clear(1); lcd.Clear(2); lcd.InverseRow(2, 0x80); |
medvdv | 2:e3c117a9b81b | 100 | |
medvdv | 2:e3c117a9b81b | 101 | lcd.XY(0,1); lcd.String("Bar"); |
medvdv | 2:e3c117a9b81b | 102 | |
medvdv | 2:e3c117a9b81b | 103 | x = 0; |
medvdv | 2:e3c117a9b81b | 104 | |
medvdv | 2:e3c117a9b81b | 105 | do { |
medvdv | 2:e3c117a9b81b | 106 | lcd.Clear(2); |
medvdv | 2:e3c117a9b81b | 107 | lcd.XY(22, 1); |
medvdv | 2:e3c117a9b81b | 108 | lcd.Bar(98, x/96.0); |
medvdv | 2:e3c117a9b81b | 109 | lcd.Update(); |
medvdv | 2:e3c117a9b81b | 110 | x += 1; |
medvdv | 2:e3c117a9b81b | 111 | x %= 97; |
medvdv | 2:e3c117a9b81b | 112 | wait_ms(50); |
medvdv | 2:e3c117a9b81b | 113 | } while(! fire); |
medvdv | 2:e3c117a9b81b | 114 | |
medvdv | 2:e3c117a9b81b | 115 | lcd.Clear(0); lcd.Clear(1); lcd.Clear(2); lcd.InverseRow(2, 0x80); |
medvdv | 0:9b6c469485ea | 116 | |
medvdv | 2:e3c117a9b81b | 117 | lcd.Row(1, "Hardware Inverse All"); |
medvdv | 2:e3c117a9b81b | 118 | lcd.Update(); |
medvdv | 2:e3c117a9b81b | 119 | |
medvdv | 2:e3c117a9b81b | 120 | wait_ms(500); while(! fire) wait_ms(100); |
medvdv | 2:e3c117a9b81b | 121 | |
medvdv | 2:e3c117a9b81b | 122 | lcd.InverseMode(true); |
medvdv | 2:e3c117a9b81b | 123 | |
medvdv | 2:e3c117a9b81b | 124 | wait_ms(500); while(! fire) wait_ms(100); |
medvdv | 2:e3c117a9b81b | 125 | |
medvdv | 2:e3c117a9b81b | 126 | lcd.InverseMode(false); |
medvdv | 2:e3c117a9b81b | 127 | |
medvdv | 2:e3c117a9b81b | 128 | lcd.Clear(0); lcd.Clear(1); lcd.Clear(2); lcd.InverseRow(2, 0x80); |
medvdv | 2:e3c117a9b81b | 129 | |
medvdv | 2:e3c117a9b81b | 130 | lcd.Row(1, "Hardware Power Off / On"); |
medvdv | 2:e3c117a9b81b | 131 | lcd.Update(); |
medvdv | 2:e3c117a9b81b | 132 | |
medvdv | 2:e3c117a9b81b | 133 | wait_ms(500); while(! fire) wait_ms(100); |
medvdv | 2:e3c117a9b81b | 134 | |
medvdv | 2:e3c117a9b81b | 135 | lcd.Power(false); |
medvdv | 2:e3c117a9b81b | 136 | |
medvdv | 2:e3c117a9b81b | 137 | wait_ms(500); while(! fire) wait_ms(100); |
medvdv | 2:e3c117a9b81b | 138 | |
medvdv | 2:e3c117a9b81b | 139 | lcd.Power(true); |
medvdv | 2:e3c117a9b81b | 140 | |
medvdv | 2:e3c117a9b81b | 141 | lcd.Clear(0); lcd.Clear(1); lcd.Clear(2); |
medvdv | 2:e3c117a9b81b | 142 | |
medvdv | 2:e3c117a9b81b | 143 | lcd.Row(0, "Menu interface:"); |
medvdv | 2:e3c117a9b81b | 144 | lcd.Row(1, "Values and sub-menu"); |
medvdv | 2:e3c117a9b81b | 145 | lcd.Row(2, "Checkbox, radiobutton"); |
medvdv | 2:e3c117a9b81b | 146 | |
medvdv | 2:e3c117a9b81b | 147 | lcd.InverseRow(2, 0x80); |
medvdv | 2:e3c117a9b81b | 148 | |
medvdv | 2:e3c117a9b81b | 149 | lcd.Update(); |
medvdv | 2:e3c117a9b81b | 150 | |
medvdv | 2:e3c117a9b81b | 151 | wait_ms(500); while(! fire) wait_ms(100); |
medvdv | 2:e3c117a9b81b | 152 | |
medvdv | 2:e3c117a9b81b | 153 | lcd128menu(&lcd, menuMain, sizeof(menuMain) / sizeof(lcd128entry)); |
medvdv | 2:e3c117a9b81b | 154 | |
medvdv | 0:9b6c469485ea | 155 | } |