richard misi / Mbed 2 deprecated mbed_ssd1306

Dependencies:   mbed ssd1306_library

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers oled.cpp Source File

oled.cpp

00001 #include "mbed.h"
00002 #include "ssd1306.h"
00003 
00004 I2C i2c(p28, p27);
00005 
00006 //Host PC Baudrate (Virtual Com Port on USB)
00007 #define usbBR            115200
00008 //#define oled_adr         0x3C
00009 #define oled_adr         0x78
00010 // mbed Interface Hardware definitions
00011 DigitalOut l1(LED1);
00012 DigitalOut l2(LED2);
00013 DigitalOut l3(LED3);
00014 DigitalOut l4(LED4);
00015 
00016 // Host PC Communication channels
00017 Serial usb(USBTX, USBRX); // tx, rx
00018 SSD1306 oled(p28, p27,oled_adr);
00019 //SSD1306 oled(&i2c,oled_adr);
00020 
00021 int status1 = 0, status2 = 0;
00022 
00023 
00024 int init(void){
00025     usb.baud(usbBR); wait(0.3);
00026    i2c.frequency(400000); wait(0.3);
00027     usb.printf("Bonjour ..... OLED SSD1306\r\n");
00028 
00029     l1= 1; l2= 0; l3= 0; l4= 0; wait(0.5);
00030     l1= 0; l2= 1; l3= 0; l4= 0; wait(0.5);
00031     l1= 0; l2= 0; l3= 1; l4= 0; wait(0.5);
00032     l1= 0; l2= 0; l3= 0; l4= 1; wait(0.5);
00033     l1= 0; l2= 0; l3= 0; l4= 0; wait(0.5);
00034     oled.speed(SSD1306::Medium);
00035     oled.init();
00036     oled.cls();
00037     oled.locate(3,1);
00038     oled.printf("Hello OLED !");
00039     oled.line(6,22,114,22,SSD1306::Normal);
00040     oled.line(114,22,114,33,SSD1306::Normal);
00041     oled.line(114,33,6,33,SSD1306::Normal);
00042     oled.line(6,33,6,22,SSD1306::Normal);
00043     oled.fill(0,0);
00044     oled.redraw();
00045     return status1;
00046     }
00047 
00048 int main(void){
00049     status1= init();
00050     while(true){
00051         };
00052     return status2;
00053     }