![](/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@1:58927e4da529, 2014-02-01 (annotated)
- Committer:
- medvdv
- Date:
- Sat Feb 01 15:39:00 2014 +0000
- Revision:
- 1:58927e4da529
- Parent:
- 0:9b6c469485ea
- Child:
- 2:e3c117a9b81b
Progress bar test
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 | 0:9b6c469485ea | 15 | BusIn joy(p15,p12,p13,p16); |
medvdv | 0:9b6c469485ea | 16 | DigitalIn fire(p14); |
medvdv | 1:58927e4da529 | 17 | |
medvdv | 0:9b6c469485ea | 18 | BusOut leds(LED1,LED2,LED3,LED4); |
medvdv | 1:58927e4da529 | 19 | |
medvdv | 1:58927e4da529 | 20 | AnalogIn Pot1(p19); |
medvdv | 1:58927e4da529 | 21 | AnalogIn Pot2(p20); |
medvdv | 0:9b6c469485ea | 22 | |
medvdv | 0:9b6c469485ea | 23 | lcd128 lcd; |
medvdv | 0:9b6c469485ea | 24 | |
medvdv | 0:9b6c469485ea | 25 | char lorem[] = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."; |
medvdv | 0:9b6c469485ea | 26 | |
medvdv | 0:9b6c469485ea | 27 | void header(char* name, char* page) |
medvdv | 0:9b6c469485ea | 28 | { |
medvdv | 0:9b6c469485ea | 29 | lcd.Clear(); |
medvdv | 0:9b6c469485ea | 30 | lcd.Bold(); |
medvdv | 0:9b6c469485ea | 31 | lcd.String(name); |
medvdv | 0:9b6c469485ea | 32 | lcd.Bold(false); |
medvdv | 0:9b6c469485ea | 33 | lcd.String(page); |
medvdv | 0:9b6c469485ea | 34 | lcd.XY(0,1); |
medvdv | 0:9b6c469485ea | 35 | } |
medvdv | 0:9b6c469485ea | 36 | |
medvdv | 1:58927e4da529 | 37 | char* BANG = " BANG! "; |
medvdv | 1:58927e4da529 | 38 | |
medvdv | 0:9b6c469485ea | 39 | int main() |
medvdv | 0:9b6c469485ea | 40 | { |
medvdv | 0:9b6c469485ea | 41 | lcd.Reset(); |
medvdv | 0:9b6c469485ea | 42 | |
medvdv | 0:9b6c469485ea | 43 | // Nice header with bold first word |
medvdv | 0:9b6c469485ea | 44 | header("MBED","Application Board"); |
medvdv | 1:58927e4da529 | 45 | |
medvdv | 1:58927e4da529 | 46 | int pot = 0, old = 0; |
medvdv | 1:58927e4da529 | 47 | bool update = true; |
medvdv | 0:9b6c469485ea | 48 | |
medvdv | 1:58927e4da529 | 49 | do { |
medvdv | 1:58927e4da529 | 50 | |
medvdv | 1:58927e4da529 | 51 | pot = Pot1 * 130; |
medvdv | 1:58927e4da529 | 52 | if((old/2) != (pot/2)) update = true; // +-1 to eliminate jitter |
medvdv | 1:58927e4da529 | 53 | old = pot; |
medvdv | 1:58927e4da529 | 54 | |
medvdv | 1:58927e4da529 | 55 | if (update) { |
medvdv | 1:58927e4da529 | 56 | |
medvdv | 1:58927e4da529 | 57 | lcd.Clear(1); |
medvdv | 1:58927e4da529 | 58 | lcd.Clear(2); |
medvdv | 1:58927e4da529 | 59 | lcd.Clear(3); |
medvdv | 1:58927e4da529 | 60 | |
medvdv | 1:58927e4da529 | 61 | lcd.XY(0,1); |
medvdv | 1:58927e4da529 | 62 | lcd.Bar(LCD_X, pot / 128.0); |
medvdv | 1:58927e4da529 | 63 | |
medvdv | 1:58927e4da529 | 64 | if (fire) { |
medvdv | 1:58927e4da529 | 65 | |
medvdv | 1:58927e4da529 | 66 | lcd.Bold(true); |
medvdv | 1:58927e4da529 | 67 | lcd.Invert(true); |
medvdv | 1:58927e4da529 | 68 | lcd.XY(64-lcd.StringWidth(BANG)/2,3); |
medvdv | 1:58927e4da529 | 69 | lcd.String(BANG); |
medvdv | 1:58927e4da529 | 70 | lcd.Bold(false); |
medvdv | 1:58927e4da529 | 71 | lcd.Invert(false); |
medvdv | 1:58927e4da529 | 72 | |
medvdv | 1:58927e4da529 | 73 | } else { |
medvdv | 1:58927e4da529 | 74 | |
medvdv | 1:58927e4da529 | 75 | lcd.XY(0,2); |
medvdv | 1:58927e4da529 | 76 | lcd.String(lorem); |
medvdv | 1:58927e4da529 | 77 | |
medvdv | 1:58927e4da529 | 78 | } |
medvdv | 1:58927e4da529 | 79 | |
medvdv | 1:58927e4da529 | 80 | lcd.Update(); |
medvdv | 1:58927e4da529 | 81 | update = false; |
medvdv | 1:58927e4da529 | 82 | } |
medvdv | 1:58927e4da529 | 83 | |
medvdv | 1:58927e4da529 | 84 | wait(0.1); |
medvdv | 0:9b6c469485ea | 85 | |
medvdv | 1:58927e4da529 | 86 | if (fire) { leds = 0xf; update = true; } else leds = joy; |
medvdv | 1:58927e4da529 | 87 | |
medvdv | 1:58927e4da529 | 88 | } while(1); |
medvdv | 0:9b6c469485ea | 89 | } |