ThingPulse / esp8266-oled-ssd1306

Driver for the SSD1306 and SH1106 based 128x64, 128x32, 64x48 pixel OLED display running on ESP8266/ESP32
https://thingpulse.com
Other
2k stars 638 forks source link

declaration in setup() possible? #222

Closed tobiasfaust closed 4 years ago

tobiasfaust commented 5 years ago

Hi, global declaration of display works with SSD1306Wire display(0x3c, D3, D5); But i need the declaration of i2C Pins and i2cAddress inside of setup() because all user-defined parameters has to load from SPIFFS before. Has anyone a hint for me to solve this?

tobiasfaust commented 5 years ago

self solved ;)

#include "SSD1306Wire.h"

SSD1306Wire* ssd;

void oled_setup() {
  // Read parameters previously from SPIFFS via getParameters procedure
  Serial.print("Starting OLED 1306: (");
  Serial.print(i2caddress_oled);
  Serial.print(", ");Serial.print(pin_sda);
  Serial.print(", ");Serial.print(pin_scl);
  Serial.println(")");

  ssd = new SSD1306Wire(i2caddress_oled, pin_sda, pin_scl);
  ssd->init();

  ssd->flipScreenVertically();
  ssd->setFont(ArialMT_Plain_24);
}

void oled_loop() {
  // clear the display
  ssd->clear();
  // draw the percentage as String
  ssd->setTextAlignment(TEXT_ALIGN_CENTER);
  ssd->drawString(64, 15, String(hcsr04_level) + "%"); 
  // write the buffer to the display
  ssd->display();
}
stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.