diff --git a/twinmax/display.cpp b/twinmax/display.cpp index caef060..e1b14ec 100644 --- a/twinmax/display.cpp +++ b/twinmax/display.cpp @@ -21,10 +21,12 @@ void temporary(){ display.begin(); // display.clearDisplay(); + display.clear(true); // no need to call display() after to apply // display.drawPixel(x, y, SSD1306_WHITE) // display.drawPixel(x, y, SSD1306_BLACK) + // display.display() } void Display::send_command(const uint8_t c){ @@ -121,4 +123,35 @@ void Display::begin(){ TRANSACTION_END return; +} + +void Display::clear(){ + TRANSACTION_START + + static const uint8_t PROGMEM dlist1[] = { + DSP_PAGEADDR, + 0, // Page start address + 0xFF, // Page end (not really, but works here) + DSP_COLUMNADDR, + 0 // Column start address + }; + send_commands(dlist1, sizeof(dlist1)); + send_command(_width - 1); // Column end address + + _wire->beginTransmission(_i2caddr); + _wire->write((uint8_t) 0x40); + uint16_t count = _width * ((_height + 7) / 8); + uint8_t written = 1; + while(count--){ + if( written >= WIRE_MAX ){ + _wire->endTransmission(); + _wire->beginTransmission(_i2caddr); + _wire->write((uint8_t) 0x40); + written = 1; + } + _wire->write(0); + } + _wire->endTransmission(); + + TRANSACTION_END } \ No newline at end of file diff --git a/twinmax/display.h b/twinmax/display.h index 768e85b..dee7f42 100644 --- a/twinmax/display.h +++ b/twinmax/display.h @@ -41,6 +41,7 @@ public: void Display(const uint8_t width=128, const uint8_t height=32, const resetPin=-1); void begin(); + void clear(); protected: void send_command(const uint8_t c);