1
1
/*
2
2
Example-01_Hello.ino
3
-
3
+
4
4
This is a library written for SparkFun Qwiic OLED boards that use the SSD1306.
5
5
6
6
SparkFun sells these at its website: www.sparkfun.com
10
10
Micro OLED https://www.sparkfun.com/products/14532
11
11
Transparent OLED https://www.sparkfun.com/products/15173
12
12
"Narrow" OLED https://www.sparkfun.com/products/17153
13
-
14
-
13
+
14
+
15
15
Written by Kirk Benell @ SparkFun Electronics, March 2022
16
16
17
- This library configures and draws graphics to OLED boards that use the
17
+ This library configures and draws graphics to OLED boards that use the
18
18
SSD1306 display hardware. The library only supports I2C.
19
-
19
+
20
20
Repository:
21
21
https://github.com/sparkfun/SparkFun_Qwiic_OLED_Arduino_Library
22
22
33
33
>> Overview <<
34
34
35
35
This demo shows the basic setup of the OLED library, generating simple graphics and displaying
36
- the results on the target device.
36
+ the results on the target device.
37
37
*/
38
38
// //////////////////////////////////////////////////////////////////////////////////////
39
39
// >>> SELECT THE CONNECTED DEVICE FOR THIS EXAMPLE <<<
61
61
62
62
#if defined(TRANSPARENT)
63
63
QwiicTransparentOLED myOLED;
64
- const char * deviceName = " Transparent OLED" ;
64
+ const char *deviceName = " Transparent OLED" ;
65
65
66
66
#elif defined(NARROW)
67
67
QwiicNarrowOLED myOLED;
68
- const char * deviceName = " Narrow OLED" ;
68
+ const char *deviceName = " Narrow OLED" ;
69
69
70
70
#else
71
71
QwiicMicroOLED myOLED;
72
- const char * deviceName = " Micro OLED" ;
72
+ const char *deviceName = " Micro OLED" ;
73
73
74
74
#endif
75
75
76
-
77
76
// //////////////////////////////////////////////////////////////////////////////////////////////
78
77
// setup()
79
78
80
79
void setup ()
81
80
{
82
- delay (500 ); // Give display time to power on
81
+ delay (500 ); // Give display time to power on
83
82
84
83
// Serial on!
85
84
Serial.begin (115200 );
@@ -90,42 +89,44 @@ void setup()
90
89
Serial.println (String (deviceName));
91
90
92
91
// Initalize the OLED device and related graphics system
93
- if (!myOLED.begin ()){
92
+ if (!myOLED.begin ())
93
+ {
94
94
95
95
Serial.println (" - Device Begin Failed" );
96
- while (1 );
96
+ while (1 )
97
+ ;
97
98
}
98
99
99
100
Serial.println (" - Begin Success" );
100
101
101
102
// Do a simple test - fill a rectangle on the screen and then print hello!
102
103
103
104
// fill a rectangle on the screen that has a 4 pixel board
104
- myOLED.rectangleFill (4 , 4 , myOLED.getWidth ()- 8 , myOLED.getHeight ()- 8 );
105
+ myOLED.rectangleFill (4 , 4 , myOLED.getWidth () - 8 , myOLED.getHeight () - 8 );
105
106
106
107
String hello = " hello" ; // our message
107
108
108
109
// Center our message on the screen. Use our Font Descriptor: QW_FONT_5X7, the default
109
110
// font of the system.
110
111
111
112
// starting x position - width minus string length (font width * number of characters) / 2
112
- int x0 = (myOLED.getWidth () - QW_FONT_5X7.width * hello.length ())/ 2 ;
113
+ int x0 = (myOLED.getWidth () - QW_FONT_5X7.width * hello.length ()) / 2 ;
113
114
114
- int y0 = (myOLED.getHeight () - QW_FONT_5X7.height )/ 2 ;
115
+ int y0 = (myOLED.getHeight () - QW_FONT_5X7.height ) / 2 ;
115
116
116
117
// Draw the text - color of black (0)
117
118
myOLED.text (x0, y0, hello, 0 );
118
119
119
120
// There's nothing on the screen yet - Now send the graphics to the device
120
121
myOLED.display ();
121
122
122
- // That's it - HELLO!
123
-
123
+ // That's it - HELLO!
124
124
}
125
125
126
- // Standard Arduino loop function.
127
- void loop (){
126
+ // Standard Arduino loop function.
127
+ void loop ()
128
+ {
128
129
129
- // All loop does in sleep.
130
+ // All loop does in sleep.
130
131
delay (1000 );
131
132
}
0 commit comments