1
+ /*
2
+ Example-01_Hello.ino
1
3
2
- // Example-01_Hello.ino
3
- //
4
- // This is a library written for SparkFun Qwiic OLED boards that use the SSD1306.
5
- //
6
- // SparkFun sells these at its website: www.sparkfun.com
7
- //
8
- // Do you like this library? Help support SparkFun. Buy a board!
9
- //
10
- // Micro OLED https://www.sparkfun.com/products/14532
11
- // Transparent OLED https://www.sparkfun.com/products/15173
12
- // "Narrow" OLED https://www.sparkfun.com/products/17153
13
- //
14
- //
15
- // Written by Kirk Benell @ SparkFun Electronics, March 2022
16
- //
17
- // This library configures and draws graphics to OLED boards that use the
18
- // SSD1306 display hardware. The library only supports I2C.
19
- //
20
- // Repository:
21
- // https://github.com/sparkfun/SparkFun_Qwiic_OLED_Arduino_Library
22
- //
23
- // Documentation:
24
- // https://sparkfun.github.io/SparkFun_Qwiic_OLED_Arduino_Library/
25
- //
26
- //
27
- // SparkFun code, firmware, and software is released under the MIT License(http://opensource.org/licenses/MIT).
28
- //
29
- // SPDX-License-Identifier: MIT
30
- //
31
- // The MIT License (MIT)
32
- //
33
- // Copyright (c) 2022 SparkFun Electronics
34
- // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
35
- // associated documentation files (the "Software"), to deal in the Software without restriction,
36
- // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
37
- // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to
38
- // do so, subject to the following conditions:
39
- // The above copyright notice and this permission notice shall be included in all copies or substantial
40
- // portions of the Software.
41
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
42
- // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
43
- // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
44
- // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
45
- // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
46
-
47
- // Example 01 for the SparkFun Qwiic OLED Arduino Library
48
- //
49
- // >> Overview <<
50
- //
51
- // This demo shows the basic setup of the OLED library, generating simple graphics and displaying
52
- // the results on the target device.
53
- //
54
- // ////////////////////////////////////////////////////////////////////////////////////////
4
+ This is a library written for SparkFun Qwiic OLED boards that use the SSD1306.
5
+
6
+ SparkFun sells these at its website: www.sparkfun.com
7
+
8
+ Do you like this library? Help support SparkFun. Buy a board!
9
+
10
+ Micro OLED https://www.sparkfun.com/products/14532
11
+ Transparent OLED https://www.sparkfun.com/products/15173
12
+ "Narrow" OLED https://www.sparkfun.com/products/17153
13
+
14
+
15
+ Written by Kirk Benell @ SparkFun Electronics, March 2022
16
+
17
+ This library configures and draws graphics to OLED boards that use the
18
+ SSD1306 display hardware. The library only supports I2C.
19
+
20
+ Repository:
21
+ https://github.com/sparkfun/SparkFun_Qwiic_OLED_Arduino_Library
22
+
23
+ Documentation:
24
+ https://sparkfun.github.io/SparkFun_Qwiic_OLED_Arduino_Library/
25
+
26
+
27
+ SparkFun code, firmware, and software is released under the MIT License(http://opensource.org/licenses/MIT).
28
+
29
+ SPDX-License-Identifier: MIT
30
+
31
+ Example 01 for the SparkFun Qwiic OLED Arduino Library
32
+
33
+ >> Overview <<
34
+
35
+ This demo shows the basic setup of the OLED library, generating simple graphics and displaying
36
+ the results on the target device.
37
+ */
38
+ // //////////////////////////////////////////////////////////////////////////////////////
55
39
// >>> SELECT THE CONNECTED DEVICE FOR THIS EXAMPLE <<<
56
40
//
57
41
// The Library supports three different types of SparkFun boards. The demo uses the following
58
42
// defines to determine which device is being used. Uncomment the device being used for this demo.
59
- //
43
+
60
44
// The default is Micro OLED
61
45
62
46
#define MICRO
70
54
// Include the SparkFun qwiic OLED Library
71
55
#include < SparkFun_Qwiic_OLED.h>
72
56
57
+ // Add in our font descriptor -- so we can center the text on the scren
58
+ #include < res/qw_fnt_5x7.h>
59
+
73
60
// What device is being used in this demo
74
61
75
62
#if defined(TRANSPARENT)
@@ -88,10 +75,6 @@ const char *deviceName = "Micro OLED";
88
75
89
76
// //////////////////////////////////////////////////////////////////////////////////////////////
90
77
// setup()
91
- //
92
- // Arduino setup() function.
93
- //
94
- // Initialize our device and draw a simple graphic. That's all this example does.
95
78
96
79
void setup ()
97
80
{
@@ -123,14 +106,13 @@ void setup()
123
106
124
107
String hello = " hello" ; // our message
125
108
126
- // Lets center our message on the screen. We need to current font.
127
-
128
- QwiicFont *pFont = myOLED.getFont ();
109
+ // Center our message on the screen. Use our Font Descriptor: QW_FONT_5X7, the default
110
+ // font of the system.
129
111
130
112
// starting x position - width minus string length (font width * number of characters) / 2
131
- int x0 = (myOLED.getWidth () - pFont-> width * hello.length ()) / 2 ;
113
+ int x0 = (myOLED.getWidth () - QW_FONT_5X7. width * hello.length ()) / 2 ;
132
114
133
- int y0 = (myOLED.getHeight () - pFont-> height ) / 2 ;
115
+ int y0 = (myOLED.getHeight () - QW_FONT_5X7. height ) / 2 ;
134
116
135
117
// Draw the text - color of black (0)
136
118
myOLED.text (x0, y0 , hello, 0 );
0 commit comments