Load different fonts into uLCD.
Dependencies: 4DGL-uLCD-SE PinDetect mbed
Fork of uLCD144G2_demo by
main.cpp@11:14cf235d715f, 2016-03-14 (annotated)
- Committer:
- TimothyY
- Date:
- Mon Mar 14 18:41:55 2016 +0000
- Revision:
- 11:14cf235d715f
- Parent:
- 10:b644d6e084bc
First Commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
TimothyY | 11:14cf235d715f | 1 | // uLCD-144-G2 different fonts |
4180_1 | 0:cfcf73272647 | 2 | // |
4180_1 | 0:cfcf73272647 | 3 | #include "mbed.h" |
4180_1 | 2:75727e89a717 | 4 | #include "uLCD_4DGL.h" |
TimothyY | 10:b644d6e084bc | 5 | #include "PinDetect.h" |
4180_1 | 0:cfcf73272647 | 6 | |
4180_1 | 2:75727e89a717 | 7 | uLCD_4DGL uLCD(p9,p10,p11); // serial tx, serial rx, reset pin; |
TimothyY | 10:b644d6e084bc | 8 | PinDetect pb1(p15); |
TimothyY | 10:b644d6e084bc | 9 | PinDetect pb2(p16); |
TimothyY | 10:b644d6e084bc | 10 | PinDetect pb3(p17); |
TimothyY | 10:b644d6e084bc | 11 | |
TimothyY | 10:b644d6e084bc | 12 | int volatile sizeCount=1; //font size count, set to 1 initially |
TimothyY | 10:b644d6e084bc | 13 | int volatile fontCount=0; //font count |
TimothyY | 10:b644d6e084bc | 14 | int volatile isInterrupted=1; //indicate an interrupt |
TimothyY | 10:b644d6e084bc | 15 | |
TimothyY | 10:b644d6e084bc | 16 | //pb1 to increase font size |
TimothyY | 10:b644d6e084bc | 17 | void pb1_hit_callback (void) { |
TimothyY | 10:b644d6e084bc | 18 | if (sizeCount < 4) {sizeCount++;} |
TimothyY | 10:b644d6e084bc | 19 | uLCD.cls(); |
TimothyY | 10:b644d6e084bc | 20 | isInterrupted=1; |
TimothyY | 10:b644d6e084bc | 21 | } |
TimothyY | 10:b644d6e084bc | 22 | |
TimothyY | 10:b644d6e084bc | 23 | //pb2 to decrease font size |
TimothyY | 10:b644d6e084bc | 24 | void pb2_hit_callback (void) { |
TimothyY | 10:b644d6e084bc | 25 | if (sizeCount > 1) {sizeCount--;} |
TimothyY | 10:b644d6e084bc | 26 | uLCD.cls(); |
TimothyY | 10:b644d6e084bc | 27 | isInterrupted=1; |
TimothyY | 10:b644d6e084bc | 28 | } |
TimothyY | 10:b644d6e084bc | 29 | |
TimothyY | 10:b644d6e084bc | 30 | //pb3 changes font. Loops through default, comic sans, tahoma, and courier new |
TimothyY | 10:b644d6e084bc | 31 | void pb3_hit_callback (void) { |
TimothyY | 10:b644d6e084bc | 32 | if (fontCount < 3) {fontCount++;} |
TimothyY | 10:b644d6e084bc | 33 | else {fontCount = 0;} |
TimothyY | 10:b644d6e084bc | 34 | uLCD.cls(); |
TimothyY | 10:b644d6e084bc | 35 | isInterrupted=1; |
TimothyY | 10:b644d6e084bc | 36 | } |
4180_1 | 0:cfcf73272647 | 37 | |
4180_1 | 2:75727e89a717 | 38 | int main() |
4180_1 | 2:75727e89a717 | 39 | { |
TimothyY | 10:b644d6e084bc | 40 | pb1.mode(PullUp); |
TimothyY | 10:b644d6e084bc | 41 | pb2.mode(PullUp); |
TimothyY | 10:b644d6e084bc | 42 | pb3.mode(PullUp); |
TimothyY | 10:b644d6e084bc | 43 | wait(.01); |
TimothyY | 10:b644d6e084bc | 44 | // Setup Interrupt callback functions for a pb hit |
TimothyY | 10:b644d6e084bc | 45 | pb1.attach_deasserted(&pb1_hit_callback); |
TimothyY | 10:b644d6e084bc | 46 | pb2.attach_deasserted(&pb2_hit_callback); |
TimothyY | 10:b644d6e084bc | 47 | pb3.attach_deasserted(&pb3_hit_callback); |
TimothyY | 10:b644d6e084bc | 48 | // Start sampling pb inputs using interrupts |
TimothyY | 10:b644d6e084bc | 49 | pb1.setSampleFrequency(); |
TimothyY | 10:b644d6e084bc | 50 | pb2.setSampleFrequency(); |
TimothyY | 10:b644d6e084bc | 51 | pb3.setSampleFrequency(); |
TimothyY | 10:b644d6e084bc | 52 | uLCD.media_init(); // initialize uSD card |
TimothyY | 10:b644d6e084bc | 53 | uLCD.printf("\n Hello\n Font\n World"); |
TimothyY | 10:b644d6e084bc | 54 | while (1) { |
TimothyY | 10:b644d6e084bc | 55 | //change font settings if a button is pushed |
TimothyY | 10:b644d6e084bc | 56 | if(isInterrupted == 1) { |
TimothyY | 10:b644d6e084bc | 57 | uLCD.cls(); |
TimothyY | 10:b644d6e084bc | 58 | isInterrupted = 0; |
TimothyY | 10:b644d6e084bc | 59 | //comic sans |
TimothyY | 10:b644d6e084bc | 60 | if(fontCount == 1) { |
TimothyY | 10:b644d6e084bc | 61 | uLCD.set_sector_address(0,0); |
TimothyY | 10:b644d6e084bc | 62 | uLCD.set_font(MEDIAFONT); |
TimothyY | 10:b644d6e084bc | 63 | } |
TimothyY | 10:b644d6e084bc | 64 | //tahoma |
TimothyY | 10:b644d6e084bc | 65 | else if(fontCount == 2) { |
TimothyY | 10:b644d6e084bc | 66 | uLCD.set_sector_address(0,0xE); |
TimothyY | 10:b644d6e084bc | 67 | uLCD.set_font(MEDIAFONT); |
TimothyY | 10:b644d6e084bc | 68 | } |
TimothyY | 10:b644d6e084bc | 69 | //courier new |
TimothyY | 10:b644d6e084bc | 70 | else if(fontCount == 3) { |
TimothyY | 10:b644d6e084bc | 71 | uLCD.set_sector_address(0,0x1C); |
TimothyY | 10:b644d6e084bc | 72 | uLCD.set_font(MEDIAFONT); |
TimothyY | 10:b644d6e084bc | 73 | } |
TimothyY | 10:b644d6e084bc | 74 | //default font |
TimothyY | 10:b644d6e084bc | 75 | else { |
TimothyY | 10:b644d6e084bc | 76 | uLCD.set_sector_address(0,0); |
TimothyY | 10:b644d6e084bc | 77 | uLCD.set_font(FONT_7X8); |
TimothyY | 10:b644d6e084bc | 78 | } |
TimothyY | 10:b644d6e084bc | 79 | //increase or decrease font |
TimothyY | 10:b644d6e084bc | 80 | uLCD.text_width(sizeCount); //1X size text |
TimothyY | 10:b644d6e084bc | 81 | uLCD.text_height(sizeCount); |
TimothyY | 10:b644d6e084bc | 82 | uLCD.printf("\n Hello\n Font\n World"); |
TimothyY | 10:b644d6e084bc | 83 | } |
4180_1 | 7:7bd7397ab89f | 84 | |
4180_1 | 4:25a266a74a4c | 85 | } |
TimothyY | 10:b644d6e084bc | 86 | } |