An mbed library for the Embedded Artists QVGA OLED 2.8 inch panel

Committer:
gbloice
Date:
Wed Mar 09 19:45:23 2011 +0000
Revision:
5:b3f5d19945ff
Parent:
2:4babceb1bfc2
Fixed example with conditional compilation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gbloice 5:b3f5d19945ff 1 #ifdef COMPILE_EXAMPLE1_CODE_EAQVGAOLED
gbloice 5:b3f5d19945ff 2
gbloice 2:4babceb1bfc2 3 #include "mbed.h"
gbloice 2:4babceb1bfc2 4 #include "EAQVGAOLED.h"
gbloice 2:4babceb1bfc2 5
gbloice 2:4babceb1bfc2 6 Serial pc(USBTX, USBRX); // tx, rx
gbloice 2:4babceb1bfc2 7
gbloice 2:4babceb1bfc2 8 int main() {
gbloice 2:4babceb1bfc2 9 EAQVGAOLED display = EAQVGAOLED(p5, p6, p7, p8, p9, p10);
gbloice 2:4babceb1bfc2 10
gbloice 2:4babceb1bfc2 11 display.background(BLACK);
gbloice 2:4babceb1bfc2 12 display.foreground(DARK_GRAY);
gbloice 2:4babceb1bfc2 13 display.cls();
gbloice 2:4babceb1bfc2 14
gbloice 2:4babceb1bfc2 15 display.printf("Hello from mbed");
gbloice 2:4babceb1bfc2 16
gbloice 2:4babceb1bfc2 17 bool inEscape = false; // Flag, set when in an escape sequence
gbloice 2:4babceb1bfc2 18 bool inCursor = false; // Flag, set when in a cursor sequence
gbloice 2:4babceb1bfc2 19
gbloice 2:4babceb1bfc2 20 // Loop drawing characters from USB onto the display
gbloice 2:4babceb1bfc2 21 while(1) {
gbloice 2:4babceb1bfc2 22
gbloice 2:4babceb1bfc2 23 if (pc.readable()) {
gbloice 2:4babceb1bfc2 24 char inChar = pc.getc();
gbloice 2:4babceb1bfc2 25 // The terminal sends escape sequences for cursor keys,
gbloice 2:4babceb1bfc2 26 // these need to be converted to control characters
gbloice 2:4babceb1bfc2 27 if (inCursor) {
gbloice 2:4babceb1bfc2 28 switch(inChar) {
gbloice 2:4babceb1bfc2 29 case 'A':
gbloice 2:4babceb1bfc2 30 display.putc(CURSOR_UP);
gbloice 2:4babceb1bfc2 31 break;
gbloice 2:4babceb1bfc2 32 case 'B':
gbloice 2:4babceb1bfc2 33 display.putc(CURSOR_DOWN);
gbloice 2:4babceb1bfc2 34 break;
gbloice 2:4babceb1bfc2 35 case 'C':
gbloice 2:4babceb1bfc2 36 display.putc(CURSOR_RIGHT);
gbloice 2:4babceb1bfc2 37 break;
gbloice 2:4babceb1bfc2 38 case 'D':
gbloice 2:4babceb1bfc2 39 display.putc(CURSOR_LEFT);
gbloice 2:4babceb1bfc2 40 break;
gbloice 2:4babceb1bfc2 41 default:
gbloice 2:4babceb1bfc2 42 display.putc(inChar);
gbloice 2:4babceb1bfc2 43 break;
gbloice 2:4babceb1bfc2 44 }
gbloice 2:4babceb1bfc2 45 inCursor = false;
gbloice 2:4babceb1bfc2 46 }
gbloice 2:4babceb1bfc2 47 else if (inEscape) {
gbloice 2:4babceb1bfc2 48 if (inChar == 91) {
gbloice 2:4babceb1bfc2 49 inCursor = true;
gbloice 2:4babceb1bfc2 50 }
gbloice 2:4babceb1bfc2 51 else {
gbloice 2:4babceb1bfc2 52 display.putc(inChar);
gbloice 2:4babceb1bfc2 53 }
gbloice 2:4babceb1bfc2 54 inEscape = false;
gbloice 2:4babceb1bfc2 55 }
gbloice 2:4babceb1bfc2 56 else {
gbloice 2:4babceb1bfc2 57 switch (inChar) {
gbloice 2:4babceb1bfc2 58 case '+':
gbloice 2:4babceb1bfc2 59 display.backlightControl(true);
gbloice 2:4babceb1bfc2 60 break;
gbloice 2:4babceb1bfc2 61 case '-':
gbloice 2:4babceb1bfc2 62 display.backlightControl(false);
gbloice 2:4babceb1bfc2 63 break;
gbloice 2:4babceb1bfc2 64 case 27:
gbloice 2:4babceb1bfc2 65 inEscape = true;
gbloice 2:4babceb1bfc2 66 break;
gbloice 2:4babceb1bfc2 67 default:
gbloice 2:4babceb1bfc2 68 display.putc(inChar);
gbloice 2:4babceb1bfc2 69 break;
gbloice 2:4babceb1bfc2 70 }
gbloice 2:4babceb1bfc2 71 }
gbloice 2:4babceb1bfc2 72 pc.printf("Got char %d, inEscape: %d, inCursor: %d\r\n", inChar, inEscape, inCursor);
gbloice 2:4babceb1bfc2 73
gbloice 2:4babceb1bfc2 74 }
gbloice 2:4babceb1bfc2 75 }
gbloice 2:4babceb1bfc2 76 }
gbloice 5:b3f5d19945ff 77 #endif