You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
add return values to drawString & drawStringMaxWidth (#365)
* get rid of utf8ascii()
Make the drawString*() functions and getStringWidth() directly convert
UTF-8 on the fly if needed. This saves an extra malloc for the converted
string in most cases which then needs to be free()d and allows to count
drawn chars even for UTF-8 strings later.
Keep the utf8ascii() function to not break the API for derived classes.
* drawStringInternal: return number of chars drawn
Return the nuber of characters that was drawn. If this is less then the
string length, then the text was too long for the display. This allows
e.g. for custom word wrapping.
* drawString: return number of characters drawn
* drawStringMaxWidth: return chars written in first line
This allows do scroll easily through longer texts, by noting the number
of chars drawn in first line and then starting the text with this offset
in the next display cycle
* drawStringMaxWidth: fix UTF-8 width calculation
* add SSD1306ScrollVerticalDemo example
this shows how the return value of drawStringMaxWidth() can be used
// or #include "SH1106Wire.h", legacy include: `#include "SH1106.h"`
30
+
// For a connection via I2C using brzo_i2c (must be installed) include
31
+
// #include <brzo_i2c.h> // Only needed for Arduino 1.6.5 and earlier
32
+
// #include "SSD1306Brzo.h"
33
+
// #include "SH1106Brzo.h"
34
+
// For a connection via SPI include
35
+
// #include <SPI.h> // Only needed for Arduino 1.6.5 and earlier
36
+
// #include "SSD1306Spi.h"
37
+
// #include "SH1106Spi.h"
38
+
39
+
// Use the corresponding display class:
40
+
41
+
// Initialize the OLED display using SPI
42
+
// D5 -> CLK
43
+
// D7 -> MOSI (DOUT)
44
+
// D0 -> RES
45
+
// D2 -> DC
46
+
// D8 -> CS
47
+
// SSD1306Spi display(D0, D2, D8);
48
+
// or
49
+
// SH1106Spi display(D0, D2);
50
+
51
+
// Initialize the OLED display using brzo_i2c
52
+
// D3 -> SDA
53
+
// D5 -> SCL
54
+
// SSD1306Brzo display(0x3c, D3, D5);
55
+
// or
56
+
// SH1106Brzo display(0x3c, D3, D5);
57
+
58
+
// Initialize the OLED display using Wire library
59
+
SSD1306Wire display(0x3c, SDA, SCL); // ADDRESS, SDA, SCL - SDA and SCL usually populate automatically based on your board's pins_arduino.h e.g. https://github.com/esp8266/Arduino/blob/master/variants/nodemcu/pins_arduino.h
60
+
// SH1106Wire display(0x3c, SDA, SCL);
61
+
62
+
// UTF-8 sprinkled within, because it tests special conditions in the char-counting code
63
+
const String loremipsum = "Lorem ipsum dolor sit ämet, "
64
+
"consetetur sadipscing elitr, sed diam nonümy eirmöd "
65
+
"tempor invidunt ut labore et dolore mägnä aliquyam erat, "
66
+
"sed diam voluptua. At vero eos et accusam et justo duo "
67
+
"dolores et ea rebum. Stet clita kasd gubergren, no sea "
68
+
"takimata sanctus est Lorem ipsum dolor sit amet. "
0 commit comments