1
+ /* !
2
+ * @file WipperSnapper_I2C_Driver_Out_Ssd1306.h
3
+ *
4
+ * Device driver for a SSD1306 OLED Display
5
+ *
6
+ * Adafruit invests time and resources providing this open source code,
7
+ * please support Adafruit and open-source hardware by purchasing
8
+ * products from Adafruit!
9
+ *
10
+ * Copyright (c) Brent Rubell for Adafruit Industries 2025
11
+ *
12
+ * MIT license, all text here must be included in any redistribution.
13
+ *
14
+ */
15
+
16
+ #ifndef WIPPERSNAPPER_I2C_DRIVER_OUT_SSD1306_H
17
+ #define WIPPERSNAPPER_I2C_DRIVER_OUT_SSD1306_H
18
+
19
+ #include " WipperSnapper_I2C_Driver_Out.h"
20
+ #include < Adafruit_SSD1306.h>
21
+ #include < Arduino.h>
22
+
23
+ #define DEFAULT_WIDTH 128
24
+ #define DEFAULT_HEIGHT 64
25
+ #define DEFAULT_ADDR 0x3C
26
+ #define PIN_OLED_RESET -1
27
+
28
+ /* !
29
+ @brief Class that provides a driver interface for a SSD1306
30
+ OLED Display
31
+ */
32
+ class WipperSnapper_I2C_Driver_Out_Ssd1306
33
+ : public WipperSnapper_I2C_Driver_Out {
34
+
35
+ public:
36
+ /* ******************************************************************************/
37
+ /* !
38
+ @brief Constructor for a SSD1306 OLED display.
39
+ @param i2c
40
+ The I2C interface.
41
+ @param sensorAddress
42
+ 7-bit device address.
43
+ */
44
+ /* ******************************************************************************/
45
+ WipperSnapper_I2C_Driver_Out_Ssd1306 (TwoWire *i2c,
46
+ uint16_t sensorAddress)
47
+ : WipperSnapper_I2C_Driver_Out(i2c, sensorAddress) {
48
+ _i2c = i2c;
49
+ _sensorAddress = sensorAddress;
50
+ _width = DEFAULT_WIDTH;
51
+ _height = DEFAULT_HEIGHT;
52
+ }
53
+
54
+ /* !
55
+ @brief Destructor for a SSD1306 OLED display.
56
+ */
57
+ ~WipperSnapper_I2C_Driver_Out_Ssd1306 () {
58
+ if (_display != nullptr ) {
59
+ delete _display;
60
+ _display = nullptr ;
61
+ }
62
+ }
63
+
64
+ /* !
65
+ @brief Initializes the SSD1306 display and begins I2C.
66
+ @returns True if initialized successfully, False otherwise.
67
+ */
68
+ bool begin () {
69
+ _display = new Adafruit_SSD1306 (_width, _height, &_i2c, PIN_OLED_RESET);
70
+ bool did_begin = _display->begin (SSD1306_SWITCHCAPVCC, DEFAULT_ADDR);
71
+ if (! did_begin)
72
+ return false ;
73
+
74
+ // Show initial display buffer contents on the screen --
75
+ // the library initializes this with an Adafruit splash screen.
76
+ _display->display ();
77
+ delay (2000 );
78
+ // Clear the buffer
79
+ _display->clearDisplay ();
80
+ // Set the text size
81
+
82
+ return true ;
83
+ }
84
+
85
+
86
+ protected:
87
+ Adafruit_SSD1306 *_display = nullptr ; // /< Pointer to the Adafruit_SSD1306 object
88
+ uint8_t _width, _height, _text_sz; // /< Width and height of the display
89
+ };
90
+
91
+ #endif // WIPPERSNAPPER_I2C_DRIVER_OUT_SSD1306_H
0 commit comments