Skip to content

Commit 476ae39

Browse files
committed
2 parents 8f0453b + af4732f commit 476ae39

File tree

1 file changed

+45
-63
lines changed

1 file changed

+45
-63
lines changed

examples/Example-01_Hello/Example-01_Hello.ino

+45-63
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,46 @@
1+
/*
2+
Example-01_Hello.ino
13
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+
////////////////////////////////////////////////////////////////////////////////////////
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
@@ -70,6 +54,9 @@
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)
@@ -88,10 +75,6 @@ const char *deviceName = "Micro OLED";
8875

8976
////////////////////////////////////////////////////////////////////////////////////////////////
9077
// setup()
91-
//
92-
// Arduino setup() function.
93-
//
94-
// Initialize our device and draw a simple graphic. That's all this example does.
9578

9679
void setup()
9780
{
@@ -123,14 +106,13 @@ void setup()
123106

124107
String hello = "hello"; // our message
125108

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.
129111

130112
// 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;
132114

133-
int y0 = (myOLED.getHeight() - pFont->height) / 2;
115+
int y0 = (myOLED.getHeight() - QW_FONT_5X7.height) / 2;
134116

135117
// Draw the text - color of black (0)
136118
myOLED.text(x0, y0, hello, 0);

0 commit comments

Comments
 (0)