Example code to test SSD1331 96x64 OLED display on STM32F401RE Nucleo board, using two candidate libraries

Dependencies:   RGB_OLED_SSD1331 mbed ssd1331

Committer:
kkado
Date:
Wed Aug 02 22:15:08 2017 +0000
Revision:
0:233a05c86eb0
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kkado 0:233a05c86eb0 1 //OLED_RST PA_12
kkado 0:233a05c86eb0 2 //DC PA_11
kkado 0:233a05c86eb0 3 //SCK PA_5
kkado 0:233a05c86eb0 4 //MOSI PA_7
kkado 0:233a05c86eb0 5 //OLED_CS PC_9
kkado 0:233a05c86eb0 6
kkado 0:233a05c86eb0 7 /*
kkado 0:233a05c86eb0 8 #include "mbed.h"
kkado 0:233a05c86eb0 9 #include "SSD1331.h"
kkado 0:233a05c86eb0 10
kkado 0:233a05c86eb0 11 int main(){
kkado 0:233a05c86eb0 12 //Init the screen (CS, RST, DC, MOSI, MISO, SCLK)
kkado 0:233a05c86eb0 13 SSD1331 oled(PC_9, PA_12, PA_11, PA_7, NC, PA_5);
kkado 0:233a05c86eb0 14 oled.drawLine(0, 0, 95, 0, Yellow);
kkado 0:233a05c86eb0 15 }
kkado 0:233a05c86eb0 16 */
kkado 0:233a05c86eb0 17
kkado 0:233a05c86eb0 18 #include "mbed.h"
kkado 0:233a05c86eb0 19 #include "ssd1331.h"
kkado 0:233a05c86eb0 20
kkado 0:233a05c86eb0 21 ssd1331 oled(PC_9, PA_12, PA_11, PA_7, NC, PA_5); // cs, res, dc, miso(nc), sck (KL25z)
kkado 0:233a05c86eb0 22
kkado 0:233a05c86eb0 23 //char Time[50],Date[50];
kkado 0:233a05c86eb0 24 //void gettime();
kkado 0:233a05c86eb0 25
kkado 0:233a05c86eb0 26 uint8_t main() {
kkado 0:233a05c86eb0 27
kkado 0:233a05c86eb0 28 while(1){
kkado 0:233a05c86eb0 29
kkado 0:233a05c86eb0 30 oled.Fill_Screen(oled.toRGB(255,0,0)); //red
kkado 0:233a05c86eb0 31 wait_ms(500);
kkado 0:233a05c86eb0 32 oled.Fill_Screen(oled.toRGB(0,255,0)); //green
kkado 0:233a05c86eb0 33 wait_ms(500);
kkado 0:233a05c86eb0 34 oled.Fill_Screen(oled.toRGB(0,0,255)); //blue
kkado 0:233a05c86eb0 35 wait_ms(500);
kkado 0:233a05c86eb0 36 oled.Fill_Screen(oled.toRGB(255,255,255)); //white
kkado 0:233a05c86eb0 37 wait_ms(500);
kkado 0:233a05c86eb0 38
kkado 0:233a05c86eb0 39 oled.cls(); // clear screen to black
kkado 0:233a05c86eb0 40
kkado 0:233a05c86eb0 41 oled.circle (20, 40, 30 ,oled.toRGB(0,0,255) , 1); //fill circle
kkado 0:233a05c86eb0 42 oled.circle (20, 40, 30 ,oled.toRGB(255,255,255) , 0); //circle
kkado 0:233a05c86eb0 43 oled.circle (20, 60, 40 ,oled.toRGB(255,0,0) , 0); //circle
kkado 0:233a05c86eb0 44 oled.line( 0, 0, width, height, oled.toRGB(0,255,255)); //line
kkado 0:233a05c86eb0 45 oled.line( width, 0, 0, height, oled.toRGB(255,0,255)); //line
kkado 0:233a05c86eb0 46 //oled.rectangle(10,10,90,60,oled.toRGB(255,255,0)); //rectangle
kkado 0:233a05c86eb0 47 //oled.fillrectangle(20,20,40,40,oled.toRGB(255,255,255),oled.toRGB(0,255,0)); //fillrectangle
kkado 0:233a05c86eb0 48
kkado 0:233a05c86eb0 49 for(uint8_t y = 9; y >= 0; y--) {
kkado 0:233a05c86eb0 50 oled.contrast(y); // set contrast level
kkado 0:233a05c86eb0 51 oled.foreground(oled.toRGB(255,255,255)); // set text colour
kkado 0:233a05c86eb0 52 oled.locate(1, 10); // set text start location
kkado 0:233a05c86eb0 53 oled.printf("%d",y); // std printf
kkado 0:233a05c86eb0 54 wait_ms(300);
kkado 0:233a05c86eb0 55 }
kkado 0:233a05c86eb0 56
kkado 0:233a05c86eb0 57 wait_ms(1000);
kkado 0:233a05c86eb0 58 oled.contrast(9); // set contrast to maximum
kkado 0:233a05c86eb0 59 wait_ms(2000);
kkado 0:233a05c86eb0 60 oled.cls();
kkado 0:233a05c86eb0 61
kkado 0:233a05c86eb0 62 oled.SetFontSize(HIGH); // set tall font
kkado 0:233a05c86eb0 63 oled.foreground(oled.toRGB(0,255,0)); // set text colour
kkado 0:233a05c86eb0 64 oled.locate(0, 10);
kkado 0:233a05c86eb0 65 oled.printf( "HIGH 12345");
kkado 0:233a05c86eb0 66
kkado 0:233a05c86eb0 67 oled.SetFontSize(WIDE); // set text to wide
kkado 0:233a05c86eb0 68 oled.foreground(oled.toRGB(0,0,255));
kkado 0:233a05c86eb0 69 oled.locate(0, 28);
kkado 0:233a05c86eb0 70 oled.printf( "WIDE 123");
kkado 0:233a05c86eb0 71
kkado 0:233a05c86eb0 72 oled.SetFontSize(WH); // set text to wide and tall
kkado 0:233a05c86eb0 73 oled.foreground(oled.toRGB(255,0,0));
kkado 0:233a05c86eb0 74 oled.locate(0, 40);
kkado 0:233a05c86eb0 75 oled.printf( "WH 123");
kkado 0:233a05c86eb0 76
kkado 0:233a05c86eb0 77 oled.SetFontSize(NORMAL); // set text to normal
kkado 0:233a05c86eb0 78 oled.foreground(oled.toRGB(255,255,255));
kkado 0:233a05c86eb0 79
kkado 0:233a05c86eb0 80 oled.ScrollSet(0,8,18,1,0); // set scroll function
kkado 0:233a05c86eb0 81 oled.Scrollstart(); // start scroll
kkado 0:233a05c86eb0 82
kkado 0:233a05c86eb0 83 //gettime();wait(1);gettime();wait(1);gettime();wait(1);
kkado 0:233a05c86eb0 84 oled.ScrollSet(0,8,18,-2,0);
kkado 0:233a05c86eb0 85 oled.Scrollstart();
kkado 0:233a05c86eb0 86 //gettime();wait(1);gettime();wait(1);gettime();wait(1);
kkado 0:233a05c86eb0 87
kkado 0:233a05c86eb0 88 oled.ScrollSet(0,8,18,3,0);
kkado 0:233a05c86eb0 89 oled.Scrollstart();
kkado 0:233a05c86eb0 90
kkado 0:233a05c86eb0 91 //gettime();wait(1);gettime();wait(1);gettime();wait(1);
kkado 0:233a05c86eb0 92
kkado 0:233a05c86eb0 93 oled.ScrollSet(0,8,18,-4,0);
kkado 0:233a05c86eb0 94 oled.Scrollstart();
kkado 0:233a05c86eb0 95
kkado 0:233a05c86eb0 96 //gettime();wait(1);gettime();wait(1);gettime();wait(1);
kkado 0:233a05c86eb0 97
kkado 0:233a05c86eb0 98 oled.Scrollstop(); // stop scroll
kkado 0:233a05c86eb0 99 wait(1);
kkado 0:233a05c86eb0 100 }
kkado 0:233a05c86eb0 101 }
kkado 0:233a05c86eb0 102
kkado 0:233a05c86eb0 103 /*
kkado 0:233a05c86eb0 104 void gettime()
kkado 0:233a05c86eb0 105 {
kkado 0:233a05c86eb0 106 time_t seconds = time(NULL);
kkado 0:233a05c86eb0 107 strftime(Time,40,"%H:%M:%S %a", localtime(&seconds));
kkado 0:233a05c86eb0 108 strftime(Date,40,"%d-%b-%Y", localtime(&seconds));
kkado 0:233a05c86eb0 109 oled.locate(0, 0);
kkado 0:233a05c86eb0 110 oled.printf(Time);
kkado 0:233a05c86eb0 111 }
kkado 0:233a05c86eb0 112 */