You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -115,7 +115,7 @@ The following architectures are supported in the Arduino Library.
115
115
116
116
Below are a few of those processors populated on Arduino boards from the [SparkFun catalog](https://www.sparkfun.com/categories/242). You will need to make sure to check the associated hookup guides for additional information about compatible cables, drivers, or board add-ons.
117
117
118
-
<divclass="grid cards hide col-4"markdown>
118
+
<divclass="grid cards col-4"markdown>
119
119
<!-- ----------WHITE SPACE BETWEEN PRODUCTS---------- -->
Copy file name to clipboardExpand all lines: examples/docs/ex_01_hello.md
+87-32
Original file line number
Diff line number
Diff line change
@@ -10,40 +10,85 @@ A simple example to show the basic setup and use of the SparkFun Qwiic OLED Libr
10
10
* Using the current font to center text on the screen.
11
11
* Displaying the graphics on the screen
12
12
13
+
14
+
13
15
## Setup
14
16
15
17
After installing this library in your local Arduino environment, begin with a standard Arduino sketch, and include the header file for this library.
18
+
19
+
16
20
```C++
17
-
// Include the SparkFun qwiic OLED Library
21
+
// Include the SparkFun Qwiic OLED Library
18
22
#include<SparkFun_Qwiic_OLED.h>
19
23
```
20
-
The next step is to declare the object for the SparkFun qwiic OLED device used. Like most Arduino sketches, this is done at a global scope (after the include file declaration), not within the ```setup()``` or ```loop()``` functions.
21
24
22
-
The user selects from one of the following classes:
The next step is to declare the object for the SparkFun Qwiic OLED device used. Like most Arduino sketches, this is done at a global scope (after the include file declaration), not within the ```setup()``` or ```loop()``` functions.
30
27
31
-
The Example code supports all of the SparkFun Qwiic OLED boards. To select the board being used, uncomment the `#define` for the demo board.
28
+
The user selects from one of the following classes:
The example code supports all of the SparkFun Qwiic OLED boards. By default, the Qwiic Micro OLED is selected. To select a different board being used, add a single line comment (i.e. `//`) in front of "`QwiicMicroOLED myOLED;`" and uncomment the device being used for the demo board.
32
68
33
-
For this example, the Qwiic Micro OLED is used.
34
-
```C++
35
-
#defineMICRO
36
-
//#define NARROW
37
-
//#define TRANSPARENT
38
-
```
39
-
Which results in myOLED being declared as:
40
69
41
70
```C++
42
71
QwiicMicroOLED myOLED;
72
+
//QwiicTransparentOLED myOLED;
73
+
//QwiicNarrowOLED myOLED;
74
+
//Qwiic1in3OLED myOLED;
75
+
43
76
```
77
+
78
+
79
+
!!! note
80
+
As of version 1.0.2+, users will need to use the class as explained above instead of using a `#define`.
81
+
82
+
```C++
83
+
#define MICRO
84
+
//#define NARROW
85
+
//#define TRANSPARENT
86
+
```
87
+
88
+
44
89
## Initialization
45
90
46
-
In the ```setup()``` function of this sketch, like all of the SparkFun qwiic libraries, the device is initialized by calling the ```begin()``` method. This method returns a value of ```true``` on success, or ```false``` on failure.
91
+
In the ```setup()``` function of this sketch, like all of the SparkFun Qwiic Arduino libraries, the device is initialized by calling the ```begin()``` method. This method returns a value of ```true``` on success, or ```false``` on failure.
47
92
48
93
```C++
49
94
voidsetup()
@@ -68,42 +113,52 @@ void setup()
68
113
69
114
Serial.println("- Begin Success");
70
115
116
+
// Do a simple test - fill a rectangle on the screen and then print hello!...
117
+
118
+
}
71
119
```
72
120
121
+
122
+
73
123
## Drawing Graphics
74
124
75
-
Once the device is enabled, the rest of the setup() function is devoted to drawing a simple graphic on the target device.
125
+
Once the device is enabled, the rest of the `setup()` function is devoted to drawing a simple graphic on the target device.
126
+
127
+
76
128
77
129
### Filled Rectangle
78
130
79
131
First, draw a filled rectangle on the screen - leave a 4 pixel boarder at the end of the screen. Note that the `getWidth()` and `getHeight()` method are used to get the devices screen size.
80
132
81
133
```C++
82
-
// fill a rectangle on the screen that has a 4 pixel board
The next part of our graphic is a message centered in the drawn rectangle. To do the centering, the current font is accessed from the device, and the size of a character in the font is used to calculate the text position on the screen.
88
138
89
-
Once the position is determined, the message is drawn on the display in black (0 for a color value).
139
+
140
+
### Centered Text
141
+
142
+
The next part of our graphic is a message centered in the drawn rectangle. To do the centering, the current font is accessed from the device, and the size of a character in the font is used to calculate the text position on the screen. Once the position is determined, the message is drawn on the display in black (0 for a color value).
90
143
91
144
```C++
92
145
String hello = "hello"; // our message
93
146
94
-
// Lets center our message on the screen. We need to current font.
147
+
// Center our message on the screen. Get the screen size of the "hello" string,
148
+
// calling the getStringWidth() and getStringHeight() methods on the oled
95
149
96
-
QwiicFont * pFont = myOLED.getFont();
150
+
// starting x position - screen width minus string width / 2
151
+
int x0 = (myOLED.getWidth() - myOLED.getStringWidth(hello)) / 2;
97
152
98
-
// starting x position - width minus string length (font width * number of characters) / 2
99
-
int x0 = (myOLED.getWidth() - pFont->width * hello.length())/2;
100
-
101
-
int y0 = (myOLED.getHeight() - pFont->height)/2;
153
+
// starting y position - screen height minus string height / 2
154
+
int y0 = (myOLED.getHeight() - myOLED.getStringHeight(hello)) / 2;
102
155
103
156
// Draw the text - color of black (0)
104
157
myOLED.text(x0, y0, hello, 0);
105
158
```
106
159
160
+
161
+
107
162
### Displaying the Graphics
108
163
109
164
The last step is sending the graphics to the device. This is accomplished by calling the `display()` method.
@@ -113,6 +168,6 @@ The last step is sending the graphics to the device. This is accomplished by cal
113
168
myOLED.display();
114
169
```
115
170
116
-
And that's in - the graphic is displayed on the OLED device.
171
+
And that's it - the graphic is displayed on the OLED device.
0 commit comments