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- // ////////////////////////////////////////////////////////////////////////////////////////
55- // >>> SELECT THE CONNECTED DEVICE FOR THIS EXAMPLE <<<
56- //
57- // The Library supports three different types of SparkFun boards. The demo uses the following
58- // defines to determine which device is being used. Uncomment the device being used for this demo.
59- //
60- // The default is Micro OLED
4+ This demo shows the basic setup of the OLED library, generating simple graphics and displaying
5+ the results on the target device.
616
62- #define MICRO
63- // #define NARROW
64- // #define TRANSPARENT
7+ This is a library written for SparkFun Qwiic OLED boards that use the SSD1306.
658
66- // ////////////////////////////////////////////////////////////////////////////////////////
9+ This library configures and draws graphics to OLED boards that use the
10+ SSD1306 display hardware. The library only supports I2C.
6711
68- # include < stdint.h >
12+ SparkFun sells these at its website: www.sparkfun.com
6913
70- // Include the SparkFun qwiic OLED Library
71- #include < SparkFun_Qwiic_OLED.h>
14+ Do you like this library? Help support SparkFun. Buy a board!
7215
73- // What device is being used in this demo
16+ Micro OLED https://www.sparkfun.com/products/14532
17+ Transparent OLED https://www.sparkfun.com/products/15173
18+ "Narrow" OLED https://www.sparkfun.com/products/17153
7419
75- #if defined(TRANSPARENT)
76- QwiicTransparentOLED myOLED;
77- const char *deviceName = " Transparent OLED" ;
20+ Written by Kirk Benell @ SparkFun Electronics, March 2022
7821
79- #elif defined(NARROW)
80- QwiicNarrowOLED myOLED;
81- const char *deviceName = " Narrow OLED" ;
22+ Repository:
23+ https://github.com/sparkfun/SparkFun_Qwiic_OLED_Arduino_Library
8224
83- #else
84- QwiicMicroOLED myOLED;
85- const char *deviceName = " Micro OLED" ;
25+ Documentation:
26+ https://sparkfun.github.io/SparkFun_Qwiic_OLED_Arduino_Library/
8627
87- #endif
28+ SparkFun code, firmware, and software is released under the MIT License(http://opensource.org/licenses/MIT).
29+ */
8830
89- // //////////////////////////////////////////////////////////////////////////////////////////////
90- // setup()
91- //
92- // Arduino setup() function.
93- //
94- // Initialize our device and draw a simple graphic. That's all this example does.
31+ #include < SparkFun_Qwiic_OLED.h> // http://librarymanager/All#SparkFun_Qwiic_Graphic_OLED
32+
33+ // The Library supports three different types of SparkFun boards. The demo uses the following
34+ // defines to determine which device is being used. Uncomment the device being used for this demo.
35+
36+ QwiicMicroOLED myOLED;
37+ // QwiicTransparentOLED myOLED;
38+ // QwiicNarrowOLED myOLED;
9539
9640void setup ()
9741{
98- delay (500 ); // Give display time to power on
99-
100- // Serial on!
10142 Serial.begin (115200 );
43+ Serial.println (" Running OLED example" );
10244
103- Serial.println (" \n\r -----------------------------------" );
104-
105- Serial.print (" Running Example 01 on: " );
106- Serial.println (String (deviceName));
45+ Wire.begin ();
10746
10847 // Initalize the OLED device and related graphics system
109- if (! myOLED.begin ())
48+ if (myOLED.begin () == false )
11049 {
111-
112- Serial.println (" - Device Begin Failed" );
113- while (1 )
50+ Serial.println (" Device begin failed. Freezing..." );
51+ while (true )
11452 ;
11553 }
116-
117- Serial.println (" - Begin Success" );
54+ Serial.println (" Begin success" );
11855
11956 // Do a simple test - fill a rectangle on the screen and then print hello!
12057
121- // fill a rectangle on the screen that has a 4 pixel board
58+ // Fill a rectangle on the screen that has a 4 pixel board
12259 myOLED.rectangleFill (4 , 4 , myOLED.getWidth () - 8 , myOLED.getHeight () - 8 );
12360
12461 String hello = " hello" ; // our message
12562
126- // Lets center our message on the screen. We need to current font.
63+ // Let's center our message on the screen. We need the current font.
12764
12865 QwiicFont *pFont = myOLED.getFont ();
12966
130- // starting x position - width minus string length (font width * number of characters) / 2
67+ // Starting x position - width minus string length (font width * number of characters) / 2
13168 int x0 = (myOLED.getWidth () - pFont->width * hello.length ()) / 2 ;
13269
13370 int y0 = (myOLED.getHeight () - pFont->height ) / 2 ;
@@ -141,10 +78,7 @@ void setup()
14178 // That's it - HELLO!
14279}
14380
144- // Standard Arduino loop function.
14581void loop ()
14682{
147-
148- // All loop does in sleep.
149- delay (1000 );
83+ delay (1000 ); // Do nothing
15084}
0 commit comments