Skip to content

Commit bd092b3

Browse files
authored
Merge pull request #41 from sparkfun/ExposeInit
Add public initDisplay
2 parents 06b7e24 + 226d70a commit bd092b3

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ scrollVertLeft KEYWORD2
4747
scrollStop KEYWORD2
4848
flipVertical KEYWORD2
4949
flipHorizontal KEYWORD2
50+
initDisplay KEYWORD2
5051

5152
getX KEYWORD2
5253
getY KEYWORD2

src/SFE_MicroOLED.cpp

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ boolean MicroOLED::begin(uint8_t deviceAddress, TwoWire &wirePort)
306306
return (true);
307307
}
308308

309-
/** \brief Initialisation of MicroOLED Library - common to all begin methods. PRIVATE.
309+
/** \brief Initialisation of MicroOLED Library - common to all begin methods.
310310
311311
Setup IO pins for the chosen interface then send initialisation commands to the SSD1306 controller inside the OLED.
312312
*/
@@ -318,17 +318,31 @@ void MicroOLED::beginCommon()
318318
setDrawMode(NORM);
319319
setCursor(0, 0);
320320

321-
// Display reset routine
322-
pinMode(rstPin, OUTPUT); // Set RST pin as OUTPUT
323-
digitalWrite(rstPin, HIGH); // Initially set RST HIGH
324-
delay(5); // VDD (3.3V) goes high at start, lets just chill for 5 ms
325-
digitalWrite(rstPin, LOW); // Bring RST low, reset the display
326-
delay(10); // wait 10ms
327-
digitalWrite(rstPin, HIGH); // Set RST HIGH, bring out of reset
321+
if(rstPin != 255)
322+
{
323+
// Display reset routine
324+
pinMode(rstPin, OUTPUT); // Set RST pin as OUTPUT
325+
digitalWrite(rstPin, HIGH); // Initially set RST HIGH
326+
delay(5); // VDD (3.3V) goes high at start, lets just chill for 5 ms
327+
digitalWrite(rstPin, LOW); // Bring RST low, reset the display
328+
delay(10); // wait 10ms
329+
digitalWrite(rstPin, HIGH); // Set RST HIGH, bring out of reset
330+
}
328331

329332
// Display Init sequence for 64x48 OLED module
330333
command(DISPLAYOFF); // 0xAE
331334

335+
initDisplay();
336+
337+
command(DISPLAYON); //--turn on oled panel
338+
}
339+
340+
/** \brief Set CGRAM and display settings
341+
342+
Set the unique SSD1306 settings for the MicroOLED setup.
343+
*/
344+
void MicroOLED::initDisplay(bool clearDisplay)
345+
{
332346
command(SETDISPLAYCLOCKDIV); // 0xD5
333347
command(0x80); // the suggested ratio 0x80
334348

@@ -361,8 +375,8 @@ void MicroOLED::beginCommon()
361375
command(SETVCOMDESELECT); // 0xDB
362376
command(0x40);
363377

364-
command(DISPLAYON); //--turn on oled panel
365-
clear(ALL); // Erase hardware memory inside the OLED controller to avoid random data in memory.
378+
if(clearDisplay)
379+
clear(ALL); // Erase hardware memory inside the OLED controller to avoid random data in memory.
366380
}
367381

368382
//Calling this function with nothing sets the debug port to Serial

src/SFE_MicroOLED.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class MicroOLED : public Print
152152
{
153153
public:
154154
// Constructor(s)
155-
MicroOLED(uint8_t rst); // I2C - leaving the address currently undefined
155+
MicroOLED(uint8_t rst = 255); // I2C - leaving the address currently undefined
156156
MicroOLED(uint8_t rst, uint8_t dc); // I2C
157157
MicroOLED(uint8_t rst, uint8_t dc, uint8_t cs); // SPI
158158
MicroOLED(uint8_t rst, uint8_t dc, uint8_t cs, uint8_t wr, uint8_t rd,
@@ -232,6 +232,8 @@ class MicroOLED : public Print
232232
//Set the max number of bytes set in a given I2C transaction
233233
uint8_t i2cTransactionSize = 32; //Default to ATmega328 limit
234234

235+
void initDisplay(bool clearDisplay = true); //Set CGRAM settings. Useful if display gets corrupt.
236+
235237
private:
236238
uint8_t csPin, dcPin, rstPin;
237239
uint8_t wrPin, rdPin, dPins[8];

0 commit comments

Comments
 (0)