display i2c
Dependencies: mbed SSD1308_128x64_I2C USBDevice
Diff: main.cpp
- Revision:
- 1:00053cb70ac5
- Parent:
- 0:2ded56b8407d
- Child:
- 2:d86478c0f5da
diff -r 2ded56b8407d -r 00053cb70ac5 main.cpp --- a/main.cpp Tue Jun 19 20:00:10 2012 +0000 +++ b/main.cpp Sat Jun 30 14:44:39 2012 +0000 @@ -1,205 +1,233 @@ -/* mbed Seeed 128x64 OLED Test - * http://www.seeedstudio.com/depot/grove-oled-display-12864-p-781.html?cPath=163_167 - * - * Copyright (c) 2012 Wim Huiskamp - * Released under the MIT License: http://mbed.org/license/mit - * - * version 0.2 Initial Release - */ -#include "mbed.h" -#include "FixedWidthFont.h" -#include "SSD1308.h" - -//Pin Defines for I2C Bus -//#define D_SDA p9 -//#define D_SCL p10 -#define D_SDA p28 -#define D_SCL p27 -I2C i2c(D_SDA, D_SCL); - -//Host PC Baudrate (Virtual Com Port on USB) -#define D_BAUDRATE 9600 -//#define D_BAUDRATE 57600 - -// mbed Interface Hardware definitions -DigitalOut myled1(LED1); -DigitalOut myled2(LED2); -DigitalOut myled3(LED3); -DigitalOut heartbeatLED(LED4); - -// Host PC Communication channels -Serial pc(USBTX, USBRX); // tx, rx - -// Instantiate OLED -SSD1308 oled = SSD1308(i2c, SSD1308_SA0); - -void show_menu() { - pc.printf("0: Exit\n\r"); - pc.printf("1: Show Menu\n\r"); - pc.printf("2: Send Message\n\r"); - pc.printf("3: \n\r"); - pc.printf("4: \n\r"); - pc.printf("5: \n\r"); - pc.printf("6: \n\r"); - pc.printf("7: \n\r"); - pc.printf("A: \n\r"); - pc.printf("B: \n\r"); - pc.printf("P: \n\r"); - pc.printf("\n\r"); -} - - -void oled_Test() { - pc.printf("OLED test start\r"); - - oled.setDisplayOff(); - pc.printf("display off\r\n"); - wait(0.5); - - oled.setDisplayOn(); - pc.printf("display on\r\n"); - wait(0.5); - - oled.clearDisplay(); - pc.printf("display cleared\r\n"); - wait(0.5); - - oled.fillDisplay(); - pc.printf("display filled\r\n"); - wait(0.5); - - oled.clearDisplay(); - pc.printf("display cleared\r\n"); - wait(0.5); - - oled.writeString(0, 0, 8, "Foobar!!"); - pc.printf("printed something\r\n"); - wait(3); - - oled.writeString(1, 8, 8, "baz quux"); - pc.printf("printed something\r\n"); - wait(3); - - oled.writeString(2, 0, 272, "a long, rather lengthy, extended string passage thing, eh, that just goes on, and on, and on, and on, and on, and on, and on, yes, further, continuing, extending, expanding beyond all reason or sanity!!!!! and yet, there's more! so much more! for ever and ever, oh yeah"); - pc.printf("printed something\r\n"); - wait(3); - - pc.printf("OLED test done\r\n"); -} - -// Variables for Heartbeat and Status monitoring -Ticker heartbeat; -bool heartbeatflag=false; - -// Local functions -void clear_screen() { -//ANSI Terminal Commands - pc.printf("\x1B[2J"); - pc.printf("\x1B[H"); -} - - -void init_interfaces() { - // Init Host PC communication, default is 9600 - pc.baud(D_BAUDRATE); - - // Init I/F hardware -// i2c.frequency(100000); - i2c.frequency(400000); // according to the spec the max bitrate for the SSD1308 is 400 kbit/s -} - - -// Heartbeat monitor -void pulse() { - heartbeatLED = !heartbeatLED; -} - -void heartbeat_start() { - heartbeat.attach(&pulse, 0.5); -} - -void heartbeat_stop() { - heartbeat.detach(); -} - - -int main() { - bool running=true; - char command; - - init_interfaces(); - - heartbeat_start(); - - clear_screen(); - - pc.printf("Hello World!\n\r"); - -// Quick test - oled_Test(); - - while(1) { - myled1 = 1; - wait(0.2); - - myled1 = 0; - wait(0.2); - pc.printf("*"); - } - - -// Interactive Test - show_menu(); - - while(running) { - - if(pc.readable()) { - command = pc.getc(); - pc.printf("command= %c \n\r", command); - - switch (command) { - case '0' : - pc.printf("Done\n\r"); - running = false; - break; - - case '1' : - show_menu(); - break; - - case '2' : - pc.printf("Hello World!\n\r"); - break; - - case '3' : - break; - - case '4' : - break; - - case '5' : - break; - case '6' : - break; - - case '7' : - break; - - case 'A' : - break; - - case 'B' : - - break; - - case 'P' : - - break; - - } //switch - }//if - }//while - - pc.printf("Bye World!\n\r"); -}//main - +/* mbed Seeed 128x64 OLED Test + * http://www.seeedstudio.com/depot/grove-oled-display-12864-p-781.html?cPath=163_167 + * + * Copyright (c) 2012 Wim Huiskamp + * Released under the MIT License: http://mbed.org/license/mit + * + * version 0.2 Initial Release + */ +#include "mbed.h" +//#include "FixedWidthFont.h" +#include "mbed_logo.h" +#include "SSD1308.h" + + +//Pin Defines for I2C Bus +//#define D_SDA p9 +//#define D_SCL p10 +#define D_SDA p28 +#define D_SCL p27 +I2C i2c(D_SDA, D_SCL); + +//Host PC Baudrate (Virtual Com Port on USB) +#define D_BAUDRATE 9600 +//#define D_BAUDRATE 57600 + +// mbed Interface Hardware definitions +DigitalOut myled1(LED1); +DigitalOut myled2(LED2); +DigitalOut myled3(LED3); +DigitalOut heartbeatLED(LED4); + +// Host PC Communication channels +Serial pc(USBTX, USBRX); // tx, rx + +// Instantiate OLED +SSD1308 oled = SSD1308(i2c, SSD1308_SA0); + +void show_menu() { + pc.printf("0: Exit\n\r"); + pc.printf("1: Show Menu\n\r"); + pc.printf("2: Send Message\n\r"); + pc.printf("3: Fill Display\n\r"); + pc.printf("4: Display cleared\n\r"); + pc.printf("5: Display off\n\r"); + pc.printf("6: Display on\n\r"); + pc.printf("7: Display Invert\n\r"); + pc.printf("8: Display Normal\n\r"); + pc.printf("9: Display Bitmap\n\r"); +// pc.printf("A: \n\r"); +// pc.printf("B: \n\r"); +// pc.printf("C: \n\r"); +// pc.printf("D: \n\r"); +// pc.printf("E: \n\r"); +// pc.printf("F: \n\r"); +// pc.printf("\n\r"); + +} + + +void oled_Test() { + pc.printf("OLED test start\r"); + + oled.writeString(0, 0, 13, "Hello World !"); + pc.printf("Printed something\r\n"); + wait(3); + + oled.writeString(1, 0, 8, "baz quux"); + pc.printf("Printed something\r\n"); + wait(3); + +// oled.writeString(4, 0, 272, "a long, rather lengthy, extended string passage thing, eh, that just goes on, and on, and on, and on, and on, and on, and on, yes, further, continuing, extending, expanding beyond all reason or sanity!!!!! and yet, there's more! so much more! for ever and ever, oh yeah"); +// pc.printf("Printed something\r\n"); +// wait(3); + + oled.fillDisplay(0xAA); + pc.printf("Display filled\r\n"); + wait(3); + + oled.setDisplayOff(); + pc.printf("Display off\r\n"); + wait(0.5); + + oled.setDisplayOn(); + pc.printf("Display on\r\n"); + wait(0.5); + + oled.clearDisplay(); + pc.printf("Display cleared\r\n"); + wait(0.5); + + oled.writeString(0, 0, 11, "Bye World !"); + pc.printf("Printed something\r\n"); + wait(3); + + pc.printf("OLED test done\r\n"); +} + +// Variables for Heartbeat and Status monitoring +Ticker heartbeat; +bool heartbeatflag=false; + +// Local functions +void clear_screen() { +//ANSI Terminal Commands + pc.printf("\x1B[2J"); + pc.printf("\x1B[H"); +} + + +void init_interfaces() { + // Init Host PC communication, default is 9600 + pc.baud(D_BAUDRATE); + + // Init I/F hardware +// i2c.frequency(100000); + i2c.frequency(400000); // according to the spec the max bitrate for the SSD1308 is 400 kbit/s +} + + +// Heartbeat monitor +void pulse() { + heartbeatLED = !heartbeatLED; +} + +void heartbeat_start() { + heartbeat.attach(&pulse, 0.5); +} + +void heartbeat_stop() { + heartbeat.detach(); +} + + +int main() { + bool running=true; + char command; + + init_interfaces(); + + heartbeat_start(); + + clear_screen(); + + pc.printf("Hello World!\n\r"); + +#if(0) +// Quick test + oled_Test(); + + while(1) { + myled1 = 1; + wait(0.2); + + myled1 = 0; + wait(0.2); + pc.printf("*"); + } +#else +// Interactive Test + show_menu(); + + while(running) { + + if(pc.readable()) { + command = pc.getc(); + pc.printf("command= %c \n\r", command); + + switch (command) { + case '0' : + pc.printf("Done\n\r"); + running = false; + break; + + case '1' : + show_menu(); + break; + + case '2' : + pc.printf("Hello World!\n\r"); + oled.writeString(0, 0, 13, "Hello World !"); + break; + + case '3' : + pc.printf("Fill Display 0xA5\n\r"); + oled.fillDisplay(0xA5); + break; + + case '4' : + pc.printf("Display cleared\r\n"); + oled.clearDisplay(); + break; + + case '5' : + pc.printf("Display off\r\n"); + oled.setDisplayOff(); + break; + case '6' : + pc.printf("Display on\r\n"); + oled.setDisplayOn(); + break; + + case '7' : + pc.printf("Display Invert\r\n"); + oled.setDisplayInverse(); + break; + + case '8' : + pc.printf("Display Normal\r\n"); + oled.setDisplayNormal(); + break; + + case '9' : + pc.printf("Display bitmap\r\n"); + oled.writeBitmap((PAGES*COLUMNS), (uint8_t*) mbed_logo); + + break; + + case 'A' : + + break; + + case 'B' : + + break; + + } //switch + }//if + }//while +#endif + + pc.printf("Bye World!\n\r"); +}//main +