1+ /*
2+ Example-01_Hello.ino
3+
4+ This is a library written for SparkFun Qwiic OLED boards that use the SSD1306.
15
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- // ////////////////////////////////////////////////////////////////////////////////////////
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+ // //////////////////////////////////////////////////////////////////////////////////////
5539// >>> SELECT THE CONNECTED DEVICE FOR THIS EXAMPLE <<<
5640//
5741// The Library supports three different types of SparkFun boards. The demo uses the following
5842// defines to determine which device is being used. Uncomment the device being used for this demo.
59- //
43+
6044// The default is Micro OLED
6145
6246#define MICRO
7054// Include the SparkFun qwiic OLED Library
7155#include < SparkFun_Qwiic_OLED.h>
7256
57+ // Add in our font descriptor -- so we can center the text on the scren
58+ #include < res/qw_fnt_5x7.h>
59+
7360// What device is being used in this demo
7461
7562#if defined(TRANSPARENT)
@@ -89,10 +76,6 @@ const char * deviceName = "Micro OLED";
8976
9077// //////////////////////////////////////////////////////////////////////////////////////////////
9178// setup()
92- //
93- // Arduino setup() function.
94- //
95- // Initialize our device and draw a simple graphic. That's all this example does.
9679
9780void setup ()
9881{
@@ -122,14 +105,13 @@ void setup()
122105
123106 String hello = " hello" ; // our message
124107
125- // Lets center our message on the screen. We need to current font.
126-
127- QwiicFont * pFont = myOLED.getFont ();
108+ // Center our message on the screen. Use our Font Descriptor: QW_FONT_5X7, the default
109+ // font of the system.
128110
129111 // starting x position - width minus string length (font width * number of characters) / 2
130- int x0 = (myOLED.getWidth () - pFont-> width * hello.length ())/2 ;
112+ int x0 = (myOLED.getWidth () - QW_FONT_5X7. width * hello.length ())/2 ;
131113
132- int y0 = (myOLED.getHeight () - pFont-> height )/2 ;
114+ int y0 = (myOLED.getHeight () - QW_FONT_5X7. height )/2 ;
133115
134116 // Draw the text - color of black (0)
135117 myOLED.text (x0, y0, hello, 0 );
0 commit comments