日本語
oled
jsdo
Wemos

概要

wemos d1でoledやってみた。
drawBitmapやってみた。

写真

MVC-008F.JPG

サンプルコード

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>


Adafruit_SSD1306 oled(16);
int x = 0;

static const unsigned char PROGMEM bmp[] = {


0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 112, 3, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 112, 3, 128, 0, 0, 112, 0, 0, 3, 128, 0, 0, 0, 0, 0, 0, 112, 3, 128, 0, 0, 240, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 112, 3, 128, 0, 0, 224, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 112, 255, 254, 15, 248, 224, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 112, 255, 254, 15, 248, 224, 0, 0, 3, 0, 0, 0, 0, 0, 0, 3, 254, 255, 254, 15, 249, 255, 252, 15, 255, 255, 224, 0, 0, 0, 0, 3, 254, 56, 112, 14, 57, 255, 252, 15, 255, 255, 224, 0, 0, 0, 0, 0, 112, 60, 112, 14, 59, 221, 220, 15, 255, 255, 224, 0, 0, 0, 0, 0, 112, 28, 112, 14, 59, 157, 220, 12, 3, 0, 224, 0, 0, 0, 0, 0, 115, 255, 255, 142, 63, 189, 220, 12, 3, 0, 224, 0, 0, 0, 0, 0, 115, 255, 255, 142, 63, 59, 220, 12, 3, 0, 224, 0, 0, 0, 0, 0, 115, 255, 255, 142, 62, 59, 156, 12, 3, 0, 224, 0, 0, 0, 0, 0, 116, 7, 0, 14, 60, 123, 156, 12, 3, 0, 224, 0, 0, 0, 0, 0, 126, 15, 0, 14, 56, 115, 156, 12, 3, 0, 224, 0, 0, 0, 0, 3, 255, 255, 255, 14, 56, 247, 156, 12, 3, 0, 224, 0, 0, 0, 0, 7, 253, 255, 255, 14, 57, 231, 28, 15, 255, 255, 224, 0, 0, 0, 0, 3, 241, 255, 255, 15, 251, 207, 28, 15, 255, 255, 224, 0, 0, 0, 0, 3, 112, 60, 120, 15, 255, 207, 28, 15, 255, 255, 224, 0, 0, 0, 0, 0, 112, 56, 112, 15, 255, 158, 28, 12, 3, 0, 224, 0, 0, 0, 0, 0, 112, 124, 112, 14, 7, 60, 28, 12, 3, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 

};

void setup()
{
    Serial.begin(115200);
    while (!Serial) delay(250);
    Serial.println("\nok");
    oled.begin(SSD1306_SWITCHCAPVCC, 0x3c);
    oled.clearDisplay();
    oled.setTextColor(WHITE);
    oled.setTextSize(2);
    oled.setCursor(0, 0);
    oled.print("oled 1");
    oled.display();
}
void loop() 
{
    oled.clearDisplay();
    if (x < -128)
    {
        x = 128;
    }
    oled.drawBitmap(x, 0, bmp, 128, 64, WHITE);
    oled.display();
    x = x - 2;
    delay(100);
}


ビットマップのソースを作るツール作った。

ビットマップデータは、static const unsigned char PROGMEMの配列で、ソースに書かなくてはいけない。
128*64で、8192bit。1024byte。大変です。そこで

ビットマップを生成して、ソースに変換するツールを作った。

成果物

http://jsdo.it/ohisama1/UdiN

以上。