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
An example that shows drawing simple shapes using the SparkFun Qwiic OLED Library.
3
+
An example that shows drawing simple shapes using the SparkFun Qwiic OLED Library.
4
4
5
5
**Key Demo Features**
6
6
@@ -9,144 +9,216 @@ An example that shows drawing simple shapes using the SparkFun Qwiic OLED Libra
9
9
* Drawing and erasing graphics quickly
10
10
* XOR operations using raster operators
11
11
12
+
13
+
12
14
## Setup
13
15
14
16
After installing this library in your local Arduino environment, begin with a standard Arduino sketch, and include the header file for this library.
17
+
18
+
15
19
```C++
16
-
// Include the SparkFun qwiic OLED Library
20
+
// Include the SparkFun Qwiic OLED Library
17
21
#include<SparkFun_Qwiic_OLED.h>
18
22
```
19
-
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.
20
23
21
-
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.
26
+
27
+
The user selects from one of the following classes:
29
28
30
-
The Example code supports all of the SparkFun Qwiic OLED boards. To select the board being used, uncomment the `#define` for the demo board.
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.
31
67
32
-
For this example, the Qwiic Micro OLED is used.
33
-
```C++
34
-
#defineMICRO
35
-
//#define NARROW
36
-
//#define TRANSPARENT
37
-
```
38
-
Which results in myOLED being declared as:
39
68
40
69
```C++
41
70
QwiicMicroOLED myOLED;
71
+
//QwiicTransparentOLED myOLED;
72
+
//QwiicNarrowOLED myOLED;
73
+
//Qwiic1in3OLED myOLED;
74
+
42
75
```
43
76
77
+
78
+
!!! note
79
+
As of version 1.0.2+, users will need to use the class as explained above instead of using a `#define`.
80
+
81
+
```C++
82
+
#define MICRO
83
+
//#define NARROW
84
+
//#define TRANSPARENT
85
+
```
86
+
87
+
88
+
44
89
## Drawing Shapes
45
90
91
+
!!! note
92
+
As of version 1.0.2+, the modular functions have a slightly different name. Some functions defined in the example code will have the `_` removed or words spelled out. For example, version v1.0.1 and below defined the function to test the line as `line_test_1()` while version v1.0.2+ defined the function as `lineTest1()`.
93
+
46
94
The shapes drawn are broken into a set of functions that perform one test, which is part of the overall example.
47
95
96
+
97
+
48
98
###Lines
49
99
50
100
This test starts with a short, horizontal line that is animated from the top to bottom of the display. After each iteration, the line size is increased and the animating sequence repeated.
51
101
52
-
To animate the line, the display is erased, then the line drawn. Once the line is draw, the updated graphics is sent to the OLED device by calling the `display()` method.
102
+
To animate the line, the display is erased, then the line drawn. Once the line is draw, the updated graphics is sent to the OLED device by calling the `display()` method.
53
103
54
104
!!! note
55
-
When `display()` is called, only the range of modified pixels is sent to the OLED device, greatly reducing the data transferred for small graphic changes.
105
+
When `display()` is called, only the range of modified pixels is sent to the OLED device, greatly reducing the data transferred for small graphic changes.
56
106
57
107
This is demonstrated by this test. When small lines are drawn, the update rate is fast, but as the line length increases, the update rate of the device is noticeably slower. A longer line requires more data to be sent to the device.
58
108
59
109
```C++
60
-
voidline_test_1(void){
61
-
110
+
voidlineTest1(void)
111
+
{
62
112
int x, y, i;
63
113
64
-
int mid = width/2;
65
-
int delta = mid/8;
66
-
67
-
for(int j =1; j < 8; j++ ){
114
+
int mid = width / 2;
115
+
int delta = mid / 8;
116
+
117
+
for (int j = 1; j < 8; j++)
118
+
{
68
119
69
-
x = delta*j;
120
+
x = delta * j;
70
121
71
-
for(i=0; i < height*2; i++){
122
+
for (i = 0; i < height * 2; i++)
123
+
{
72
124
73
125
y = i % height;
74
126
myOLED.erase();
75
-
myOLED.line(mid-x, y, mid+x, y);
127
+
myOLED.line(mid - x, y, mid + x, y);
76
128
myOLED.display();
77
129
}
78
130
}
79
131
}
80
132
```
133
+
134
+
135
+
81
136
This test is followed up with a series of lines that span from a single point to the bottom of the screen, showing the flexibility of the line to raster algorithm used by the library.
82
137
83
138
```C++
84
-
void line_test_2(void){
85
-
86
-
for(int i=0; i < width; i +=6){
87
-
myOLED.line(0, 0, i, height-1);
139
+
void lineTest2(void)
140
+
{
141
+
for (int i = 0; i < width; i += 6)
142
+
{
143
+
myOLED.line(0, 0, i, height - 1);
88
144
myOLED.display();
89
145
}
90
146
delay(200);
91
147
myOLED.erase();
92
-
for(int i=width-1; i >= 0; i -=6){
93
-
myOLED.line(width-1, 0, i, height-1);
148
+
for (int i = width - 1; i >= 0; i -= 6)
149
+
{
150
+
myOLED.line(width - 1, 0, i, height - 1);
94
151
myOLED.display();
95
-
}
152
+
}
96
153
}
97
154
```
155
+
156
+
157
+
98
158
And the last line test draws a series of lines to test all three internal line drawing algorithms. Specifically:
159
+
99
160
* Angled lines drawn by the general purpose line algorithm
100
161
* Vertical lines drawn by an optimized line routine
101
162
* Horizontal lines draw by an optimized line routine
102
163
103
164
The test animates to show a growing box, giving an idea of the speed and flexibility of the system.
lineTestVerticalIterative(mid - i / 2, mid + i / 2);
131
192
myOLED.display();
132
193
delay(10);
133
194
}
134
195
}
135
196
```
136
197
198
+
199
+
137
200
### Rectangles
138
201
139
-
Several rectangle routines are shown in this example. A key test is a fast drawing routine which animates a small rectangle being drawn diagonally across the screen.
202
+
Several rectangle routines are shown in this example. A key test is a fast drawing routine which animates a small rectangle being drawn diagonally across the screen.
140
203
141
204
In this test, the rectangle is drawn, sent to the device via using `display()`, then the rectangle is drawn again, but this time in black. This effectively erases the rectangle. The position is incremented and the process loops, causing the rectangle to appear to fly across the screen.
142
205
143
206
The animation is quick, since only the portions of the screen that need updated are actually updated.
144
207
145
-
The animation algorithm:
208
+
The animation algorithm is listed in the `rectangleTestMove() function.
146
209
147
210
```C++
148
-
for(int i = 0; i < steps; i++){
149
-
211
+
void rectangleTestMove(void)
212
+
{
213
+
float steps = height;
214
+
float xinc = width / steps;
215
+
float yinc = height / steps;
216
+
int side = 10;
217
+
float x = 0;
218
+
float y = 0;
219
+
220
+
for (int i = 0; i < steps; i++)
221
+
{
150
222
// Draw the rectangle and send it to device
151
223
myOLED.rectangle(x, y, side, side);
152
224
myOLED.display(); // sends erased rect and new rect pixels to device
@@ -155,45 +227,48 @@ The animation algorithm:
155
227
myOLED.rectangle(x, y, side, side, 0);
156
228
157
229
x += xinc;
158
-
y += yinc;
230
+
y += yinc;
159
231
}
232
+
}
160
233
```
161
234
235
+
236
+
162
237
The next rectangle test draws a series of filled rectangles on the screen. The unique aspect of this test is that is uses the XOR functionally to overlay a rectangle on the device, presenting a alternating color pattern.
163
238
164
-
The XOR raster operation is set by calling the `setDrawMode()` method on the OLED device, and providing the `grROPXOR` code. This switch the device into a XOR drawing mode. Graphic operations are restored to normal by calling `setDrawMode()` and providing the `grROPCopy` code, which copies the new pixel value to the destination.
239
+
The XOR raster operation is set by calling the `setDrawMode()` method on the OLED device, and providing the `grROPXOR` code. This switch the device into a XOR drawing mode. Graphic operations are restored to normal by calling `setDrawMode()` and providing the `grROPCopy` code, which copies the new pixel value to the destination.
myOLED.setDrawMode(grROPCopy); // back to copy op (default)
178
253
}
179
254
```
180
255
181
-
### Circles
182
256
183
-
The final shape drawn by this example is a series of circles and filled circles. Using the geometry of the screen, a set of circles are drawn and displayed.
184
257
185
-
```C++
186
-
void circle_test(void){
258
+
### Circles
187
259
188
-
// Lets draw some circles that fit on the device
189
-
myOLED.circle(width/4, height/2, height/3);
260
+
The final shape drawn by this example is a series of circles and filled circles. Using the geometry of the screen, a set of circles are drawn and displayed.
0 commit comments