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
//
49
49
// >> Overview <<
50
50
//
51
51
// This demo shows the basic setup of the OLED library, generating simple graphics and displaying
52
- // the results on the target device.
52
+ // the results on the target device.
53
53
//
54
54
// ////////////////////////////////////////////////////////////////////////////////////////
55
55
// >>> SELECT THE CONNECTED DEVICE FOR THIS EXAMPLE <<<
74
74
75
75
#if defined(TRANSPARENT)
76
76
QwiicTransparentOLED myOLED;
77
- const char * deviceName = " Transparent OLED" ;
77
+ const char *deviceName = " Transparent OLED" ;
78
78
79
79
#elif defined(NARROW)
80
80
QwiicNarrowOLED myOLED;
81
- const char * deviceName = " Narrow OLED" ;
81
+ const char *deviceName = " Narrow OLED" ;
82
82
83
83
#else
84
84
QwiicMicroOLED myOLED;
85
- const char * deviceName = " Micro OLED" ;
85
+ const char *deviceName = " Micro OLED" ;
86
86
87
87
#endif
88
88
89
-
90
89
// //////////////////////////////////////////////////////////////////////////////////////////////
91
90
// setup()
92
- //
93
- // Arduino setup() function.
91
+ //
92
+ // Arduino setup() function.
94
93
//
95
94
// Initialize our device and draw a simple graphic. That's all this example does.
96
95
97
96
void setup ()
98
97
{
99
- delay (500 ); // Give display time to power on
98
+ delay (500 ); // Give display time to power on
100
99
101
100
// Serial on!
102
101
Serial.begin (115200 );
@@ -107,43 +106,45 @@ void setup()
107
106
Serial.println (String (deviceName));
108
107
109
108
// Initalize the OLED device and related graphics system
110
- if (!myOLED.begin ()){
109
+ if (!myOLED.begin ())
110
+ {
111
111
112
112
Serial.println (" - Device Begin Failed" );
113
- while (1 );
113
+ while (1 )
114
+ ;
114
115
}
115
116
116
117
Serial.println (" - Begin Success" );
117
118
118
119
// Do a simple test - fill a rectangle on the screen and then print hello!
119
120
120
121
// fill a rectangle on the screen that has a 4 pixel board
121
- myOLED.rectangleFill (4 , 4 , myOLED.getWidth ()- 8 , myOLED.getHeight ()- 8 );
122
+ myOLED.rectangleFill (4 , 4 , myOLED.getWidth () - 8 , myOLED.getHeight () - 8 );
122
123
123
124
String hello = " hello" ; // our message
124
125
125
- // Lets center our message on the screen. We need to current font.
126
+ // Lets center our message on the screen. We need to current font.
126
127
127
- QwiicFont * pFont = myOLED.getFont ();
128
+ QwiicFont *pFont = myOLED.getFont ();
128
129
129
130
// starting x position - width minus string length (font width * number of characters) / 2
130
- int x0 = (myOLED.getWidth () - pFont->width * hello.length ())/ 2 ;
131
+ int x0 = (myOLED.getWidth () - pFont->width * hello.length ()) / 2 ;
131
132
132
- int y0 = (myOLED.getHeight () - pFont->height )/ 2 ;
133
+ int y0 = (myOLED.getHeight () - pFont->height ) / 2 ;
133
134
134
135
// Draw the text - color of black (0)
135
136
myOLED.text (x0, y0 , hello, 0 );
136
137
137
138
// There's nothing on the screen yet - Now send the graphics to the device
138
139
myOLED.display ();
139
140
140
- // That's it - HELLO!
141
-
141
+ // That's it - HELLO!
142
142
}
143
143
144
- // Standard Arduino loop function.
145
- void loop (){
144
+ // Standard Arduino loop function.
145
+ void loop ()
146
+ {
146
147
147
- // All loop does in sleep.
148
+ // All loop does in sleep.
148
149
delay (1000 );
149
150
}
0 commit comments