adafruit / Adafruit_SSD1306

Arduino library for SSD1306 monochrome 128x64 and 128x32 OLEDs
http://www.adafruit.com/category/63_98
Other
1.81k stars 984 forks source link

Define OLED address instead of hard-coding #198

Closed flywire closed 3 years ago

flywire commented 3 years ago

Define OLED address like Screen Width/Height rather than hard-coding.

https://github.com/adafruit/Adafruit_SSD1306/blob/master/examples/ssd1306_128x32_i2c/ssd1306_128x32_i2c.ino#L63

if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32

https://github.com/adafruit/Adafruit_SSD1306/blob/master/examples/ssd1306_128x64_i2c/ssd1306_128x64_i2c.ino#L59

if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3D)) { // Address 0x3D for 128x64

ladyada commented 3 years ago

you can set the width/height on instantiation, thats where the allocation happens as well.

flywire commented 3 years ago

Agree but it would be nicer to use like:

...
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
#define SCREEN_ADDRESS 0x3D ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
...
  if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
...

I'd be happy to do a PR.

ladyada commented 3 years ago

that is not possible to do, a #define does not change the allocation inside the library

ladyada commented 3 years ago

wait, do mean just changing the examples? or the API?

flywire commented 3 years ago

Just the examples so SCREEN_ADDRESS (or preferred name) is identified more clearly.

ladyada commented 3 years ago

oooh ok yes thats ok! sorry we get tons of people trying to change the API... yes a PR is welcome, please note it has to pass CI https://learn.adafruit.com/contribute-to-arduino-with-git-and-github