Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 /* 00002 test OLED module (128x64/SPI) [aitendo VGM12864SPI-W] 00003 */ 00004 00005 #include "mbed.h" 00006 00007 #include "ssd1306.h" 00008 #include "standard_font.h" 00009 #include "bold_font.h" 00010 00011 // SSD1306 oled(p8 /* cs */, p9 /* reset */, p14 /* dc */, p13 /* clock */, p11 /* data */); // LPC1768 00012 // SSD1306 oled(PTA13 /* cs */, PTD5 /* reset */, PTD0 /* dc */, PTD1 /* clock */, PTD2 /* data */); // KL25Z 00013 SSD1306 oled(D10 /* cs */, D9 /* reset */, D8 /* dc */, D13 /* clock */, D11 /* data */); // KL05Z or Arduino styles 00014 00015 #define NUMFLAKES 10 00016 #define XPOS 0 00017 #define YPOS 1 00018 #define DELTAY 2 00019 00020 #define LOGO16_GLCD_HEIGHT 16 00021 #define LOGO16_GLCD_WIDTH 16 00022 static const unsigned char logo16_glcd_bmp[] = 00023 { 0x00, 0xc0, // B00000000, B11000000, 00024 0x01, 0xc0, // B00000001, B11000000, 00025 0x01, 0xc0, // B00000001, B11000000, 00026 0x03, 0xe0, // B00000011, B11100000, 00027 0xf3, 0xe0, // B11110011, B11100000, 00028 0xfe, 0xf8, // B11111110, B11111000, 00029 0x7e, 0xff, // B01111110, B11111111, 00030 0x33, 0x9f, // B00110011, B10011111, 00031 0x1f, 0xfc, // B00011111, B11111100, 00032 0x0d, 0x70, // B00001101, B01110000, 00033 0x1b, 0xa0, // B00011011, B10100000, 00034 0x3f, 0xe0, // B00111111, B11100000, 00035 0x3f, 0xf0, // B00111111, B11110000, 00036 0x7c, 0xf0, // B01111100, B11110000, 00037 0x70, 0x70, // B01110000, B01110000, 00038 0x00, 0x30 }; // B00000000, B00110000 }; 00039 00040 void testdrawbitmap(const unsigned char *bitmap, int w, int h) { 00041 uint8_t icons[NUMFLAKES][3]; 00042 srand((unsigned int)time(NULL)); // srandom(666); // whatever seed 00043 int i; 00044 00045 // initialize 00046 for (uint8_t f=0; f< NUMFLAKES; f++) { 00047 icons[f][XPOS] = rand() % SSD1306_LCDWIDTH; // display.width(); 00048 icons[f][YPOS] = 0; 00049 icons[f][DELTAY] = rand() % 5 + 1; 00050 #if 0 00051 Serial.print("x: "); 00052 Serial.print(icons[f][XPOS], DEC); 00053 Serial.print(" y: "); 00054 Serial.print(icons[f][YPOS], DEC); 00055 Serial.print(" dy: "); 00056 Serial.println(icons[f][DELTAY], DEC); 00057 #endif 00058 } 00059 00060 i = 0; 00061 while (1) { 00062 // draw each icon 00063 for (uint8_t f=0; f< NUMFLAKES; f++) { 00064 oled.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, 1); // WHITE); 00065 } 00066 oled.update(); 00067 wait(0.2); // delay(200); 00068 00069 // then erase it + move it 00070 for (uint8_t f=0; f< NUMFLAKES; f++) { 00071 oled.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, 0); // BLACK); 00072 // move it 00073 icons[f][YPOS] += icons[f][DELTAY]; 00074 // if its gone, reinit 00075 if (icons[f][YPOS] > SSD1306_LCDHEIGHT) { // display.height()) { 00076 icons[f][XPOS] = rand() % SSD1306_LCDWIDTH; // display.width(); 00077 icons[f][YPOS] = 0; 00078 icons[f][DELTAY] = rand() % 5 + 1; 00079 } 00080 } 00081 if (i++ > 100) break; 00082 } 00083 00084 } 00085 00086 void testdrawline() { 00087 for (int16_t i=0; i<SSD1306_LCDWIDTH; i+=4) { 00088 oled.line(0, 0, i, SSD1306_LCDHEIGHT-1); 00089 oled.update(); 00090 } 00091 for (int16_t i=0; i<SSD1306_LCDHEIGHT; i+=4) { 00092 oled.line(0, 0, SSD1306_LCDWIDTH-1, i); 00093 oled.update(); 00094 } 00095 wait(0.25); // delay(250); 00096 00097 oled.clear(); 00098 for (int16_t i=0; i<SSD1306_LCDWIDTH; i+=4) { 00099 oled.line(0, SSD1306_LCDHEIGHT-1, i, 0); 00100 oled.update(); 00101 } 00102 for (int16_t i=SSD1306_LCDHEIGHT-1; i>=0; i-=4) { 00103 oled.line(0, SSD1306_LCDHEIGHT-1, SSD1306_LCDWIDTH-1, i); 00104 oled.update(); 00105 } 00106 wait(0.25); // delay(250); 00107 00108 oled.clear(); 00109 for (int16_t i=SSD1306_LCDWIDTH-1; i>=0; i-=4) { 00110 oled.line(SSD1306_LCDWIDTH-1, SSD1306_LCDHEIGHT-1, i, 0); 00111 oled.update(); 00112 } 00113 for (int16_t i=SSD1306_LCDHEIGHT-1; i>=0; i-=4) { 00114 oled.line(SSD1306_LCDWIDTH-1, SSD1306_LCDHEIGHT-1, 0, i); 00115 oled.update(); 00116 } 00117 wait(0.25); // delay(250); 00118 00119 oled.clear(); 00120 for (int16_t i=0; i<SSD1306_LCDHEIGHT; i+=4) { 00121 oled.line(SSD1306_LCDWIDTH-1, 0, 0, i); 00122 oled.update(); 00123 } 00124 for (int16_t i=0; i<SSD1306_LCDWIDTH; i+=4) { 00125 oled.line(SSD1306_LCDWIDTH-1, 0, i, SSD1306_LCDHEIGHT-1); 00126 oled.update(); 00127 } 00128 wait(0.25); 00129 } 00130 00131 int main() 00132 { 00133 oled.initialise(); 00134 oled.clear(); 00135 oled.set_contrast(255); // max contrast 00136 00137 oled.drawBitmap(30, 16, logo16_glcd_bmp, 16, 16); 00138 oled.update(); 00139 wait(3); 00140 00141 testdrawline(); 00142 00143 oled.clear(); 00144 testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH); 00145 00146 oled.set_font(bold_font, 8); 00147 oled.printf("Heading\r\n"); 00148 00149 oled.set_font(standard_font, 6); 00150 oled.printf("Hello World!\r\n"); 00151 oled.printf("Some more text here...\r\n\r\n\r\n\r\n"); 00152 // oled.set_font(bold_font, 8); 00153 oled.line(127, 0, 0, 63); 00154 00155 oled.update(); 00156 wait(1); 00157 00158 int i = 0; 00159 while (1) 00160 { 00161 wait(1); 00162 oled.printf("%d\r\n", i++); 00163 oled.update(); 00164 oled.scroll_up(); 00165 } 00166 } 00167 00168 // EOF
Generated on Thu Jul 21 2022 08:05:16 by
1.7.2