diff --git a/ESP_SSD1306.cpp b/ESP_SSD1306.cpp index fb07923..3ab5c52 100644 --- a/ESP_SSD1306.cpp +++ b/ESP_SSD1306.cpp @@ -151,7 +151,9 @@ void ESP_SSD1306::drawPixel(int16_t x, int16_t y, uint16_t color) { } -ESP_SSD1306::ESP_SSD1306(int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS) : Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT) { +//constructor for SPI display , SPI value false dosnt have sance +ESP_SSD1306::ESP_SSD1306(bool SPI, int8_t SID, int8_t SCLK, int8_t DC, int8_t CS, int8_t RST) : Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT) { + spi = true; cs = CS; rst = RST; dc = DC; @@ -160,28 +162,58 @@ ESP_SSD1306::ESP_SSD1306(int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t hwSPI = false; } -// constructor for hardware SPI - we indicate DataCommand, ChipSelect, Reset -ESP_SSD1306::ESP_SSD1306(int8_t DC, int8_t RST, int8_t CS) : Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT) { - dc = DC; - rst = RST; - cs = CS; - hwSPI = true; +// constructor for hardware SPI - we indicate DataCommand, ChipSelect, Reset, or I2C with reset pin +// if SPI false DC is SDA, CS is SCL and RST is reset pin +ESP_SSD1306::ESP_SSD1306(bool SPI, int8_t DC,int8_t CS,int8_t RST) : Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT) { + spi = SPI; + if(spi){ + dc = DC; + rst = RST; + cs = CS; + hwSPI = true; + sda = scl = -1; + } else { + sclk = dc = cs = sid = -1; + sda = DC; + scl = CS; + rst = RST; + } } // initializer for I2C - we only indicate the reset pin! -ESP_SSD1306::ESP_SSD1306(int8_t reset) : -Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT) { +// SPI value of true dosnt have sance +ESP_SSD1306::ESP_SSD1306(bool SPI, int8_t SDA, int8_t SCL) : Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT) { + spi = false; + rst = sclk = dc = cs = sid = -1; + sda = SDA; + scl = SCL; +} + +// initializer for I2C - we only indicate the reset pin! +// SPI value of true dosnt have sance +ESP_SSD1306::ESP_SSD1306(bool SPI, int8_t RST) : Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT) { + spi = false; sclk = dc = cs = sid = -1; - rst = reset; + rst = RST; + sda = 4; + scl = 5; } +// initializer for I2C - we only indicate the reset pin! +// SPI value of true dosnt have sance +ESP_SSD1306::ESP_SSD1306(bool SPI) : Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT) { + spi = false; + rst = sclk = dc = cs = sid = -1; + sda = 4; + scl = 5; +} -void ESP_SSD1306::begin(uint8_t vccstate, uint8_t i2caddr, bool reset) { +void ESP_SSD1306::begin(uint8_t vccstate, uint8_t i2caddr) { _vccstate = vccstate; _i2caddr = i2caddr; // set pin directions - if (sid != -1){ + if (spi){ pinMode(dc, OUTPUT); pinMode(cs, OUTPUT); //commented for ESP8266 compatibility @@ -215,7 +247,7 @@ void ESP_SSD1306::begin(uint8_t vccstate, uint8_t i2caddr, bool reset) { else { // I2C Init - Wire.begin(); + Wire.begin(sda,scl); #ifdef __SAM3X8E__ // Force 400 KHz I2C, rawr! (Uses pins 20, 21 for SDA, SCL) TWI1->TWI_CWGR = 0; @@ -223,7 +255,7 @@ void ESP_SSD1306::begin(uint8_t vccstate, uint8_t i2caddr, bool reset) { #endif } - if (reset) { + if (rst != -1) { // Setup reset pin direction (used by both SPI and I2C) pinMode(rst, OUTPUT); digitalWrite(rst, HIGH); @@ -359,7 +391,7 @@ void ESP_SSD1306::invertDisplay(uint8_t i) { } void ESP_SSD1306::ssd1306_command(uint8_t c) { - if (sid != -1) + if (spi) { // SPI digitalWrite(cs, HIGH); //uncommented for ESP8266 compatibility @@ -474,7 +506,7 @@ void ESP_SSD1306::dim(boolean dim) { } void ESP_SSD1306::ssd1306_data(uint8_t c) { - if (sid != -1) + if (spi) { // SPI digitalWrite(cs, HIGH); //uncommented for ESP8266 compatibility @@ -515,7 +547,7 @@ void ESP_SSD1306::display(void) { ssd1306_command(1); // Page end address #endif - if (sid != -1) + if (spi) { // SPI digitalWrite(cs, HIGH); //added for ESP8266 compatibility diff --git a/ESP_SSD1306.h b/ESP_SSD1306.h index cb09d17..9baa1f8 100644 --- a/ESP_SSD1306.h +++ b/ESP_SSD1306.h @@ -146,11 +146,19 @@ Otherwise comment the line #define pgm_read_byte(addr)... class ESP_SSD1306 : public Adafruit_GFX { public: - ESP_SSD1306(int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS); - ESP_SSD1306(int8_t DC, int8_t RST, int8_t CS); //Constructor for hardware SPI - ESP_SSD1306(int8_t RST); - - void begin(uint8_t switchvcc = SSD1306_SWITCHCAPVCC, uint8_t i2caddr = SSD1306_I2C_ADDRESS, bool reset=true); + // SPI settings + ESP_SSD1306(bool SPI, int8_t SID, int8_t SCLK, int8_t DC, int8_t CS, int8_t RST); + // SPI and I2C settings + // if SPI false DC is SDA, CS is SCL and RST is reset pin + ESP_SSD1306(bool SPI, int8_t DC,int8_t CS,int8_t RST); + // I2C settings + ESP_SSD1306(bool SPI, int8_t SDA, int8_t SCL); + // I2C settings + ESP_SSD1306(bool SPI, int8_t RST); + // I2C settings + ESP_SSD1306(bool SPI = false); + + void begin(uint8_t switchvcc = SSD1306_SWITCHCAPVCC, uint8_t i2caddr = SSD1306_I2C_ADDRESS); void ssd1306_command(uint8_t c); void ssd1306_data(uint8_t c); @@ -173,7 +181,8 @@ class ESP_SSD1306 : public Adafruit_GFX { virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color); private: - int8_t _i2caddr, _vccstate, sid, sclk, dc, rst, cs; + boolean spi; + int8_t _i2caddr, _vccstate, sid, sclk, dc, rst, cs, sda, scl; void fastSPIwrite(uint8_t c); boolean hwSPI; diff --git a/examples/ESP_ssd1306_128x64_I2C/ESP_ssd1306_128x64_I2C.ino b/examples/ESP_ssd1306_128x64_I2C/ESP_ssd1306_128x64_I2C.ino index 93eddfa..39c9a29 100644 --- a/examples/ESP_ssd1306_128x64_I2C/ESP_ssd1306_128x64_I2C.ino +++ b/examples/ESP_ssd1306_128x64_I2C/ESP_ssd1306_128x64_I2C.ino @@ -19,8 +19,6 @@ // Import required libraries #include // Modification of Adafruit_SSD1306 for ESP8266 compatibility #include // Needs a little change in original Adafruit library (See README.txt file) -#include // For SPI comm (needed for not getting compile error) -#include // For I2C comm, but needed for not getting compile error /* HardWare OLED ESP8266 I2C pins @@ -126,7 +124,7 @@ const unsigned char PROGMEM demo [] = { }; -ESP_SSD1306 display(OLED_RESET); // FOR I2C +ESP_SSD1306 display(false,OLED_RESET); // FOR I2C void setup(void) diff --git a/examples/ESP_ssd1306_128x64_I2C_difpin/ESP_ssd1306_128x64_I2C_difpin.ino b/examples/ESP_ssd1306_128x64_I2C_difpin/ESP_ssd1306_128x64_I2C_difpin.ino new file mode 100644 index 0000000..4005fa7 --- /dev/null +++ b/examples/ESP_ssd1306_128x64_I2C_difpin/ESP_ssd1306_128x64_I2C_difpin.ino @@ -0,0 +1,442 @@ +/* + ****** ESP_ssd1306_128x64_I2C demo display ********* + * + * Demo for using ESP_SSD1306 library to communicate + * a ssd1306 Display with the ESP8266 board + * through hardware I2C communication + * + *********** This code is for the ESP8266*********** + * + * This is an example for Monochrome OLEDs based on SSD1306 drivers + * + * This examples uses the ESP_SSD1306 library which is a copy of the default's Adafruit_SSD1306 + * library with some modifications in order to work in the ESP8266 board. + * This library works in conjunction with the default's Adafruit_GFX library, but it's needed + * to do a little modification in that library in order to work (See README.txt file) + * +*/ + +// Import required libraries +#include // Modification of Adafruit_SSD1306 for ESP8266 compatibility +#include // Needs a little change in original Adafruit library (See README.txt file) + +/* +HardWare OLED ESP8266 I2C pins +Pin 17, GPIO14 SCL +Pin 19, GPIO15 SDA +*/ + +// Display demo definitions +#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, B11000000, + B00000001, B11000000, + B00000001, B11000000, + B00000011, B11100000, + B11110011, B11100000, + B11111110, B11111000, + B01111110, B11111111, + B00110011, B10011111, + B00011111, B11111100, + B00001101, B01110000, + B00011011, B10100000, + B00111111, B11100000, + B00111111, B11110000, + B01111100, B11110000, + B01110000, B01110000, + B00000000, B00110000 }; + +const unsigned char PROGMEM demo [] = { +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0xFF, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x01, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x03, 0xCF, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x06, 0xD7, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x06, 0xDF, 0xFF, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x05, 0x7F, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x0F, 0xFF, 0xFF, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x1F, 0xFF, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x1F, 0xFF, 0xFF, 0xFF, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x3F, 0xFF, 0xFF, 0xFF, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x3F, 0xFC, 0x00, 0x7F, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x3F, 0xFF, 0xC0, 0x1F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x3F, 0xFF, 0xE0, 0x01, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x3F, 0xFF, 0xFC, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x3F, 0xFF, 0xFF, 0xC0, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x3F, 0xFF, 0xFF, 0xFC, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x7F, 0xFF, 0xFF, 0xFF, 0xF6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x7F, 0xFF, 0xFF, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x7F, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x7F, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0xE4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x7F, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x7F, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0xE5, 0xCE, 0xDF, 0xA8, 0x77, 0xBF, 0x00, +0x00, 0x00, 0x00, 0x7F, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x87, 0xD8, 0xB2, 0xD8, 0xCC, 0xAD, 0x00, +0x00, 0x00, 0x00, 0xFF, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x87, 0x18, 0xB2, 0xD8, 0xCC, 0xAD, 0x00, +0x00, 0x00, 0x00, 0xFF, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0xE5, 0xCE, 0x9C, 0xDB, 0x77, 0x2D, 0x00, +0x00, 0x40, 0x00, 0xFF, 0xFF, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x20, 0x00, 0xFF, 0xFF, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x20, 0x00, 0xFF, 0xFF, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x0C, 0x03, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x04, 0x03, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x02, 0x07, 0x0F, 0xFF, 0xFE, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0xDF, 0xFF, 0xF8, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x01, 0x00, 0x7F, 0xFF, 0xF0, 0x00, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x80, 0xF8, 0x01, 0x18, 0x00, 0x40, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x81, 0xE6, 0x01, 0x88, 0x01, 0x80, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x43, 0xC1, 0xF8, 0xCC, 0x3F, 0x00, 0xCE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x27, 0x00, 0x0F, 0xFF, 0xE0, 0x00, 0xC6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x27, 0x00, 0x01, 0xFE, 0x00, 0x06, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x0C, 0x01, 0xE0, 0x00, 0x00, 0x06, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x0C, 0x03, 0xF4, 0x00, 0x00, 0x7A, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x18, 0x06, 0x04, 0x00, 0x05, 0xDF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x14, 0x0F, 0xC4, 0x00, 0x1D, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x23, 0x8E, 0x6D, 0xF9, 0xFD, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x46, 0x0D, 0x1F, 0x09, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x73, 0xCF, 0xFF, 0x0C, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x08, 0x49, 0x0D, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x08, 0x49, 0x0D, 0xF4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x07, 0x81, 0xF8, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x3F, 0xE7, 0xEC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + + +ESP_SSD1306 display(false,4,5); // FOR I2C + + +void setup(void) +{ + // Start Serial + Serial.begin(115200); + + // SSD1306 Init + display.begin(SSD1306_SWITCHCAPVCC); // Switch OLED + + // Show image buffer on the display hardware. + // Since the buffer is intialized with an Adafruit splashscreen + // internally, this will display the splashscreen. + display.display(); + delay(2000); + // Clear the buffer. + display.clearDisplay(); + + // draw a demo bitmap + display.drawBitmap(0, 0, demo, 128, 64, 1); // drawbitmap (X,Y,*unsigned char,W,H,1) + display.display(); + delay(2000); + display.clearDisplay(); + + // draw a single pixel + display.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! + display.display(); + delay(2000); + display.clearDisplay(); + + // draw many lines + testdrawline(); + display.display(); + delay(2000); + display.clearDisplay(); + + // draw rectangles + testdrawrect(); + display.display(); + delay(2000); + display.clearDisplay(); + + // draw multiple rectangles + testfillrect(); + display.display(); + delay(2000); + display.clearDisplay(); + + // draw mulitple circles + testdrawcircle(); + display.display(); + delay(2000); + display.clearDisplay(); + + // draw a white circle, 10 pixel radius + display.fillCircle(display.width()/2, display.height()/2, 10, WHITE); + display.display(); + delay(2000); + display.clearDisplay(); + + testdrawroundrect(); + delay(2000); + display.clearDisplay(); + + testfillroundrect(); + delay(2000); + display.clearDisplay(); + + testdrawtriangle(); + delay(2000); + display.clearDisplay(); + + testfilltriangle(); + delay(2000); + display.clearDisplay(); + + // draw the first ~12 characters in the font + testdrawchar(); + display.display(); + delay(2000); + display.clearDisplay(); + + // draw scrolling text + testscrolltext(); + delay(2000); + display.clearDisplay(); + + // text display tests + display.setTextSize(1); + display.setTextColor(WHITE); + display.setCursor(0,0); + display.println("Hello, world!"); + display.setTextColor(BLACK, WHITE); // 'inverted' text + display.println(3.141592); + display.setTextSize(2); + display.setTextColor(WHITE); + display.print("0x"); display.println(0xDEADBEEF, HEX); + display.display(); + delay(2000); + + // miniature bitmap display + display.clearDisplay(); + display.drawBitmap(30, 16, logo16_glcd_bmp, 16, 16, 1); + display.display(); + delay(2000); + + // invert the display + display.invertDisplay(true); + delay(1000); + display.invertDisplay(false); + delay(1000); + + // Fill screen + display.clearDisplay(); + display.fillScreen(WHITE); + display.display(); + delay(2000); + display.clearDisplay(); + + // draw a bitmap icon and 'animate' movement + testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH); + +} + + +void loop() { + +} + + + +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] = random(display.width()); + icons[f][YPOS] = 0; + icons[f][DELTAY] = random(5) + 1; + + Serial.print("x: "); + Serial.print(icons[f][XPOS], DEC); + Serial.print(" y: "); + Serial.print(icons[f][YPOS], DEC); + Serial.print(" dy: "); + Serial.println(icons[f][DELTAY], DEC); + } + + while (1) { + // draw each icon + for (uint8_t f=0; f< NUMFLAKES; f++) { + display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, WHITE); + } + display.display(); + delay(200); + + // then erase it + move it + for (uint8_t f=0; f< NUMFLAKES; f++) { + display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, BLACK); + // move it + icons[f][YPOS] += icons[f][DELTAY]; + // if its gone, reinit + if (icons[f][YPOS] > display.height()) { + icons[f][XPOS] = random(display.width()); + icons[f][YPOS] = 0; + icons[f][DELTAY] = random(5) + 1; + } + } + } +} + + +void testdrawchar(void) { + display.setTextSize(1); + display.setTextColor(WHITE); + display.setCursor(0,0); + + for (uint8_t i=0; i < 168; i++) { + if (i == '\n') continue; + display.write(i); + if ((i > 0) && (i % 21 == 0)) + display.println(); + } + display.display(); +} + +void testfillrect(void) { + uint8_t color = 1; + for (int16_t i=0; i0; i-=5) { + display.fillTriangle(display.width()/2, display.height()/2-i, + display.width()/2-i, display.height()/2+i, + display.width()/2+i, display.height()/2+i, WHITE); + if (color == WHITE) color = BLACK; + else color = WHITE; + display.display(); + } +} + +void testdrawroundrect(void) { + for (int16_t i=0; i=0; i-=4) { + display.drawLine(0, display.height()-1, display.width()-1, i, WHITE); + display.display(); + } + delay(250); + + display.clearDisplay(); + for (int16_t i=display.width()-1; i>=0; i-=4) { + display.drawLine(display.width()-1, display.height()-1, i, 0, WHITE); + display.display(); + } + for (int16_t i=display.height()-1; i>=0; i-=4) { + display.drawLine(display.width()-1, display.height()-1, 0, i, WHITE); + display.display(); + } + delay(250); + + display.clearDisplay(); + for (int16_t i=0; i // Modification of Adafruit_SSD1306 for ESP8266 compatibility #include // Needs a little change in original Adafruit library (See README.txt file) #include // For SPI comm (needed for not getting compile error) -#include // For I2C comm, but needed for not getting compile error /*HardWare Olimex ESP8266 SPI pins Pin 16, GPIO12 MISO (DIN) @@ -129,7 +128,7 @@ const unsigned char PROGMEM demo [] = { }; -ESP_SSD1306 display(OLED_DC, OLED_RESET, OLED_CS); // FOR SPI +ESP_SSD1306 display(true, OLED_DC, OLED_RESET, OLED_CS); // FOR SPI void setup(void)