![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
mbed display
Dependencies: mbed ssd1306_library
oled.cpp@0:79fcf18a9ae5, 2018-10-16 (annotated)
- Committer:
- RCMISbed
- Date:
- Tue Oct 16 05:23:48 2018 +0000
- Revision:
- 0:79fcf18a9ae5
mbed ssd1306
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RCMISbed | 0:79fcf18a9ae5 | 1 | #include "mbed.h" |
RCMISbed | 0:79fcf18a9ae5 | 2 | #include "ssd1306.h" |
RCMISbed | 0:79fcf18a9ae5 | 3 | |
RCMISbed | 0:79fcf18a9ae5 | 4 | I2C i2c(p28, p27); |
RCMISbed | 0:79fcf18a9ae5 | 5 | |
RCMISbed | 0:79fcf18a9ae5 | 6 | //Host PC Baudrate (Virtual Com Port on USB) |
RCMISbed | 0:79fcf18a9ae5 | 7 | #define usbBR 115200 |
RCMISbed | 0:79fcf18a9ae5 | 8 | //#define oled_adr 0x3C |
RCMISbed | 0:79fcf18a9ae5 | 9 | #define oled_adr 0x78 |
RCMISbed | 0:79fcf18a9ae5 | 10 | // mbed Interface Hardware definitions |
RCMISbed | 0:79fcf18a9ae5 | 11 | DigitalOut l1(LED1); |
RCMISbed | 0:79fcf18a9ae5 | 12 | DigitalOut l2(LED2); |
RCMISbed | 0:79fcf18a9ae5 | 13 | DigitalOut l3(LED3); |
RCMISbed | 0:79fcf18a9ae5 | 14 | DigitalOut l4(LED4); |
RCMISbed | 0:79fcf18a9ae5 | 15 | |
RCMISbed | 0:79fcf18a9ae5 | 16 | // Host PC Communication channels |
RCMISbed | 0:79fcf18a9ae5 | 17 | Serial usb(USBTX, USBRX); // tx, rx |
RCMISbed | 0:79fcf18a9ae5 | 18 | SSD1306 oled(p28, p27,oled_adr); |
RCMISbed | 0:79fcf18a9ae5 | 19 | //SSD1306 oled(&i2c,oled_adr); |
RCMISbed | 0:79fcf18a9ae5 | 20 | |
RCMISbed | 0:79fcf18a9ae5 | 21 | int status1 = 0, status2 = 0; |
RCMISbed | 0:79fcf18a9ae5 | 22 | |
RCMISbed | 0:79fcf18a9ae5 | 23 | |
RCMISbed | 0:79fcf18a9ae5 | 24 | int init(void){ |
RCMISbed | 0:79fcf18a9ae5 | 25 | usb.baud(usbBR); wait(0.3); |
RCMISbed | 0:79fcf18a9ae5 | 26 | i2c.frequency(400000); wait(0.3); |
RCMISbed | 0:79fcf18a9ae5 | 27 | usb.printf("Bonjour ..... OLED SSD1306\r\n"); |
RCMISbed | 0:79fcf18a9ae5 | 28 | |
RCMISbed | 0:79fcf18a9ae5 | 29 | l1= 1; l2= 0; l3= 0; l4= 0; wait(0.5); |
RCMISbed | 0:79fcf18a9ae5 | 30 | l1= 0; l2= 1; l3= 0; l4= 0; wait(0.5); |
RCMISbed | 0:79fcf18a9ae5 | 31 | l1= 0; l2= 0; l3= 1; l4= 0; wait(0.5); |
RCMISbed | 0:79fcf18a9ae5 | 32 | l1= 0; l2= 0; l3= 0; l4= 1; wait(0.5); |
RCMISbed | 0:79fcf18a9ae5 | 33 | l1= 0; l2= 0; l3= 0; l4= 0; wait(0.5); |
RCMISbed | 0:79fcf18a9ae5 | 34 | oled.speed(SSD1306::Medium); |
RCMISbed | 0:79fcf18a9ae5 | 35 | oled.init(); |
RCMISbed | 0:79fcf18a9ae5 | 36 | oled.cls(); |
RCMISbed | 0:79fcf18a9ae5 | 37 | oled.locate(3,1); |
RCMISbed | 0:79fcf18a9ae5 | 38 | oled.printf("Hello OLED !"); |
RCMISbed | 0:79fcf18a9ae5 | 39 | oled.line(6,22,114,22,SSD1306::Normal); |
RCMISbed | 0:79fcf18a9ae5 | 40 | oled.line(114,22,114,33,SSD1306::Normal); |
RCMISbed | 0:79fcf18a9ae5 | 41 | oled.line(114,33,6,33,SSD1306::Normal); |
RCMISbed | 0:79fcf18a9ae5 | 42 | oled.line(6,33,6,22,SSD1306::Normal); |
RCMISbed | 0:79fcf18a9ae5 | 43 | oled.fill(0,0); |
RCMISbed | 0:79fcf18a9ae5 | 44 | oled.redraw(); |
RCMISbed | 0:79fcf18a9ae5 | 45 | return status1; |
RCMISbed | 0:79fcf18a9ae5 | 46 | } |
RCMISbed | 0:79fcf18a9ae5 | 47 | |
RCMISbed | 0:79fcf18a9ae5 | 48 | int main(void){ |
RCMISbed | 0:79fcf18a9ae5 | 49 | status1= init(); |
RCMISbed | 0:79fcf18a9ae5 | 50 | while(true){ |
RCMISbed | 0:79fcf18a9ae5 | 51 | }; |
RCMISbed | 0:79fcf18a9ae5 | 52 | return status2; |
RCMISbed | 0:79fcf18a9ae5 | 53 | } |