Write the OLED(using I2C) l432KCc PIN sda scl reset

Dependencies:   Adafruit_GFX mbed

Fork of I2C_SSD1306_Helloworld_WIZwiki-W7500 by IOP

Files at this revision

API Documentation at this revision

Comitter:
bibi94
Date:
Fri Sep 21 08:24:56 2018 +0000
Parent:
13:52e9c29e2f88
Child:
15:6396392fd424
Commit message:
Change pin for nucleo l432kc

Changed in this revision

Adafruit_GFX.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/Adafruit_GFX.lib	Wed Apr 19 04:07:40 2017 +0000
+++ b/Adafruit_GFX.lib	Fri Sep 21 08:24:56 2018 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/users/kaizen/code/Adafruit_GFX/#3112550cc6a3
+http://developer.mbed.org/users/kaizen/code/Adafruit_GFX/#e31b31e3128a
--- a/main.cpp	Wed Apr 19 04:07:40 2017 +0000
+++ b/main.cpp	Fri Sep 21 08:24:56 2018 +0000
@@ -1,27 +1,346 @@
 #include "mbed.h"
 #include "Adafruit_SSD1306.h"
 
-DigitalOut myled_R(LED_RED);
+#define NUMFLAKES 10
+#define XPOS 0
+#define YPOS 1
+#define DELTAY 2
+
+
+#define LOGO16_GLCD_HEIGHT 16 
+#define LOGO16_GLCD_WIDTH  16 
+//static const unsigned char PROGMEM logo16_glcd_bmp[] ={        B00000000, B00110000 };
+    uint8_t logo16_glcd_bmp[32] =
+    { 
+        0x00, 0xC0, 0x01, 0xC0, 0x01, 0xC0, 0x03, 0xE0, 0xE3, 0xE0, 0xFE, 0xF8, 0xFE, 0xFF, 0x33, 0x9F, 0x1F, 0xFC, 0x0D, 0x70, 0x1B, 0xA0, 0x3F, 0xE0, 0x3F, 0xF0, 0x7C, 0xF0, 0x70, 0x70, 0x00, 0x30
+    };
+DigitalOut myled_R(LED1);
+
+I2C i2c(PA_10,PA_9);//sda,scl(PA_10,PA_9)
+
+Adafruit_SSD1306_I2c myOled(i2c,PB_7,0x7A,64,128);//0x3D+SA0+RW
+Serial pc(SERIAL_TX, SERIAL_RX);
+
+void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {
+  uint8_t icons[NUMFLAKES][3];
+ 
+  // initialize
+  for (uint8_t f=0; f< NUMFLAKES; f++) {
+    icons[f][XPOS] = rand()%myOled.width();
+    icons[f][YPOS] = 0;
+    icons[f][DELTAY] = rand()%5 + 1;
+    
+     pc.printf("x: %d",icons[f][XPOS]);
+    // pc.printf(icons[f][XPOS], DEC);
+     pc.printf(" y: %d",icons[f][YPOS]);
+     //pc.printf(icons[f][YPOS], DEC);
+     pc.printf(" dy: %d",icons[f][DELTAY]);
+     //pc.printfln(icons[f][DELTAY], DEC);
+  }
+
+  while (1) {
+    // draw each icon
+    for (uint8_t f=0; f< NUMFLAKES; f++) {
+      myOled.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, WHITE);
+    }
+    myOled.display();
+    wait(0.5);
+    
+    // then erase it + move it
+    for (uint8_t f=0; f< NUMFLAKES; f++) {
+      myOled.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, BLACK);
+      // move it
+      icons[f][YPOS] += icons[f][DELTAY];
+      // if its gone, reinit
+      if (icons[f][YPOS] > myOled.height()) {
+        icons[f][XPOS] = rand()%myOled.width();
+        icons[f][YPOS] = 0;
+        icons[f][DELTAY] = rand()%5 + 1;
+      }
+    }
+   }
+}
+
+
+void testdrawchar(void) {
+  myOled.setTextSize(1);
+  myOled.setTextColor(WHITE);
+  myOled.setTextCursor(0,0);
+  for (uint8_t i=0; i < 168; i++) {
+    if (i == '\n') continue;
+    myOled.writeChar(i);
+    if ((i > 0) && (i % 21 == 0))
+      myOled.printf("\n");
+  }    
+  myOled.display();
+  wait(0.5);
+}
+
+void testdrawcircle(void) {
+  for (int16_t i=0; i<myOled.height(); i+=2) {
+    myOled.drawCircle(myOled.width()/2, myOled.height()/2, i, WHITE);
+    myOled.display();
+    wait(0.5);
+  }
+}
+
+void testfillrect(void) {
+  uint8_t color = 1;
+  for (int16_t i=0; i<myOled.height()/2; i+=3) {
+    // alternate colors
+    myOled.fillRect(i, i, myOled.width()-i*2, myOled.height()-i*2, color%2);
+    myOled.display();
+    wait(0.5);
+    color++;
+  }
+}
+
+void testdrawtriangle(void) {
+  for (int16_t i=0; i<min(myOled.width(),myOled.height())/2; i+=5) {
+    myOled.drawTriangle(myOled.width()/2, myOled.height()/2-i,
+                     myOled.width()/2-i, myOled.height()/2+i,
+                     myOled.width()/2+i, myOled.height()/2+i, WHITE);
+    myOled.display();
+    wait(0.5);
+  }
+}
 
-I2C i2c(PA_10,PA_9);
+void testfilltriangle(void) {
+  uint8_t color = WHITE;
+  for (int16_t i=min(myOled.width(),myOled.height())/2; i>0; i-=5) {
+    myOled.fillTriangle(myOled.width()/2, myOled.height()/2-i,
+                     myOled.width()/2-i, myOled.height()/2+i,
+                     myOled.width()/2+i, myOled.height()/2+i, WHITE);
+    if (color == WHITE) color = BLACK;
+    else color = WHITE;
+    myOled.display();
+    wait(0.5);
+  }
+}
+
+void testdrawroundrect(void) {
+  for (int16_t i=0; i<myOled.height()/2-2; i+=2) {
+    myOled.drawRoundRect(i, i, myOled.width()-2*i, myOled.height()-2*i, myOled.height()/4, WHITE);
+    myOled.display();
+    wait(0.5);
+  }
+}
+
+void testfillroundrect(void) {
+  uint8_t color = WHITE;
+  for (int16_t i=0; i<myOled.height()/2-2; i+=2) {
+    myOled.fillRoundRect(i, i, myOled.width()-2*i, myOled.height()-2*i, myOled.height()/4, color);
+    if (color == WHITE) color = BLACK;
+    else color = WHITE;
+    myOled.display();
+    wait(0.5);
+  }
+}
+   
+void testdrawrect(void) {
+  for (int16_t i=0; i<myOled.height()/2; i+=2) {
+    myOled.drawRect(i, i, myOled.width()-2*i, myOled.height()-2*i, WHITE);
+    myOled.display();
+    wait(0.5);
+  }
+}
 
-Adafruit_SSD1306_I2c myOled(i2c,NC,0x78,64,128);
+void testdrawline() {  
+  for (int16_t i=0; i<myOled.width(); i+=4) {
+    myOled.drawLine(0, 0, i, myOled.height()-1, WHITE);
+    myOled.display();
+    wait(0.5);
+  }
+  for (int16_t i=0; i<myOled.height(); i+=4) {
+    myOled.drawLine(0, 0, myOled.width()-1, i, WHITE);
+    myOled.display();
+    wait(0.5);
+  }
+  wait(0.25);
+  
+  myOled.clearDisplay();
+  for (int16_t i=0; i<myOled.width(); i+=4) {
+    myOled.drawLine(0, myOled.height()-1, i, 0, WHITE);
+    myOled.display();
+    wait(0.5);
+  }
+  for (int16_t i=myOled.height()-1; i>=0; i-=4) {
+    myOled.drawLine(0, myOled.height()-1, myOled.width()-1, i, WHITE);
+    myOled.display();
+    wait(0.5);
+  }
+  wait(0.25);
+  
+  myOled.clearDisplay();
+  for (int16_t i=myOled.width()-1; i>=0; i-=4) {
+    myOled.drawLine(myOled.width()-1, myOled.height()-1, i, 0, WHITE);
+    myOled.display();
+    wait(0.5);
+  }
+  for (int16_t i=myOled.height()-1; i>=0; i-=4) {
+    myOled.drawLine(myOled.width()-1, myOled.height()-1, 0, i, WHITE);
+    myOled.display();
+    wait(0.5);
+  }
+  wait(0.25);
 
+  myOled.clearDisplay();
+  for (int16_t i=0; i<myOled.height(); i+=4) {
+    myOled.drawLine(myOled.width()-1, 0, 0, i, WHITE);
+    myOled.display();
+    wait(0.5);
+  }
+  for (int16_t i=0; i<myOled.width(); i+=4) {
+    myOled.drawLine(myOled.width()-1, 0, i, myOled.height()-1, WHITE); 
+    myOled.display();
+    wait(0.5);
+  }
+  wait(0.25);
+}
+
+void testscrolltext(void) {
+  myOled.setTextSize(2);
+  myOled.setTextColor(WHITE);
+  myOled.setTextCursor(10,0);
+  myOled.clearDisplay();
+  myOled.printf("scroll");
+  myOled.display();
+  wait(0.5);
+ 
+  myOled.startscrollright(0x00, 0x0F);
+  wait(0.5);
+  myOled.stopscroll();
+  wait(0.5);
+  myOled.startscrollleft(0x00, 0x0F);
+  wait(0.5);
+  myOled.stopscroll();
+  wait(0.5);    
+  myOled.startscrolldiagright(0x00, 0x07);
+  wait(0.5);
+  myOled.startscrolldiagleft(0x00, 0x07);
+  wait(0.5);
+  myOled.stopscroll();
+}
 
 int main()
 {   
-    uint16_t x=0;
-    
+  //  uint16_t x=0;
+   // pc.printf("Hello World !\n");
+    //pc.printf("%ux%u \nHellow World\r\n", myOled.width(), myOled.SD_I2C_ADDRESS());
     myOled.begin();
-    myOled.printf("%ux%u \nHellow World\r\n", myOled.width(), myOled.height());
-    myOled.display();
+    // Show image buffer on the display hardware.
+  // Since the buffer is intialized with an Adafruit splashscreen
+  // internally, this will display the splashscreen.
+  myOled.display();
+  wait(2);
+
+  // Clear the buffer.
+  myOled.clearDisplay();
+
+  // draw a single pixel
+  myOled.drawPixel(10, 10, WHITE);
+  // Show the display buffer on the hardware.
+  // NOTE: You _must_ call display after making any drawing commands
+  // to make them visible on the display hardware!
+  myOled.display();
+  wait(2);
+  myOled.clearDisplay();
+
+  // draw many lines
+  testdrawline();
+  myOled.display();
+  wait(2);
+  myOled.clearDisplay();
+
+  // draw rectangles
+  testdrawrect();
+  myOled.display();
+  wait(1);
+  myOled.clearDisplay();
+
+  // draw multiple rectangles
+  testfillrect();
+  myOled.display();
+  wait(1);
+  myOled.clearDisplay();
+
+  // draw mulitple circles
+  testdrawcircle();
+  myOled.display();
+  wait(2);
+  myOled.clearDisplay();
+
+  // draw a white circle, 10 pixel radius
+  myOled.fillCircle(myOled.width()/2, myOled.height()/2, 10, WHITE);
+  myOled.display();
+  wait(2);
+  myOled.clearDisplay();
+
+  testdrawroundrect();
+  wait(2);
+  myOled.clearDisplay();
 
-    while(1)
+  testfillroundrect();
+  wait(2);
+  myOled.clearDisplay();
+
+  testdrawtriangle();
+  wait(2);
+  myOled.clearDisplay();
+   
+  testfilltriangle();
+  wait(2);
+  myOled.clearDisplay();
+
+  // draw the first ~12 characters in the font
+  testdrawchar();
+  myOled.display();
+  wait(2);
+  myOled.clearDisplay();
+
+  // draw scrolling text
+  testscrolltext();
+  wait(2);
+  myOled.clearDisplay();
+
+  // text display tests
+  myOled.setTextSize(1);
+  myOled.setTextColor(WHITE);
+  myOled.setTextCursor(0,0);
+  //myOled.setCursor(0,0);
+  myOled.printf("Hello, world!");
+  myOled.setTextColor(BLACK, WHITE); // 'inverted' text
+  myOled.printf("3.141592");
+  myOled.setTextSize(2);
+  myOled.setTextColor(WHITE);
+  myOled.printf("0x",0xDEADBEEF);// myOled.printf(0xDEADBEEF, HEX);
+  myOled.display();
+  wait(0.5);
+  myOled.clearDisplay();
+
+  // miniature bitmap display
+  //myOled.drawBitmap(30, 16,  logo16_glcd_bmp, 16, 16, 1);
+  myOled.display();
+  wait(0.5);
+
+  // invert the display
+  myOled.invertDisplay(true);
+  wait(0.5);
+  myOled.invertDisplay(false);
+  wait(0.5);
+  myOled.clearDisplay();
+
+  // draw a bitmap icon and 'animate' movement
+  testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH);
+   /* while(1)
     {
-        myled_R = !myled_R;
-        myOled.printf("%u\r",x);
-        myOled.display();
-        x = x + 1;                  
-        wait(1.0);
-    }
+        //myOled.drawPixel(x, 32, 1);
+       // myOled.drawCircle(64,32,20,1);
+       // myOled.drawFastVLine(125,2,50,1);
+        //myled_R = !myled_R;
+        //myOled.printf("%u\r",x);
+        //myOled.display();
+        //x = x + 1;                  
+        //wait(0.5);
+    }*/
 }
--- a/mbed.bld	Wed Apr 19 04:07:40 2017 +0000
+++ b/mbed.bld	Fri Sep 21 08:24:56 2018 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/6f327212ef96
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/e95d10626187
\ No newline at end of file