-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathExample-05_ScrollFlip.ino
154 lines (123 loc) · 3.64 KB
/
Example-05_ScrollFlip.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
Example-05_ScrollFlip.ino
This demo shows the various display options - scrolling, flipping, invert.
NOTE: Scrolling isn't supported on the Transparent OLED
This library configures and draws graphics to OLED boards that use the
SSD1306 display hardware. The library only supports I2C.
SparkFun sells these at its website: www.sparkfun.com
Do you like this library? Help support SparkFun. Buy a board!
Micro OLED https://www.sparkfun.com/products/14532
Transparent OLED https://www.sparkfun.com/products/15173
"Narrow" OLED https://www.sparkfun.com/products/17153
Qwiic OLED 1.3in https://www.sparkfun.com/products/23453
Written by Kirk Benell @ SparkFun Electronics, March 2022
Repository:
https://github.com/sparkfun/SparkFun_Qwiic_OLED_Arduino_Library
Documentation:
https://sparkfun.github.io/SparkFun_Qwiic_OLED_Arduino_Library/
SparkFun code, firmware, and software is released under the MIT License(http://opensource.org/licenses/MIT).
*/
#include <SparkFun_Qwiic_OLED.h> //http://librarymanager/All#SparkFun_Qwiic_OLED
// The Library supports three different types of SparkFun boards. The demo uses the following
// defines to determine which device is being used. Uncomment the device being used for this demo.
QwiicMicroOLED myOLED;
// QwiicTransparentOLED myOLED;
// QwiicNarrowOLED myOLED;
// Qwiic1in3OLED myOLED;
int yoffset;
// Our testing functions
void scrollRight(void)
{
myOLED.scrollStop();
myOLED.scrollRight(0, 7, SCROLL_INTERVAL_2_FRAMES);
}
void scrollRightVertical(void)
{
myOLED.scrollStop();
myOLED.scrollVertRight(0, 7, SCROLL_INTERVAL_3_FRAMES);
}
void scrollLeft(void)
{
myOLED.scrollStop();
myOLED.scrollLeft(0, 7, SCROLL_INTERVAL_4_FRAMES);
}
void scrollLeftVertical(void)
{
myOLED.scrollStop();
myOLED.scrollVertLeft(0, 7, SCROLL_INTERVAL_5_FRAMES);
}
void scrollStop(void)
{
myOLED.scrollStop();
}
void flipHorizontal(void)
{
for (int i = 0; i < 6; i++)
{
myOLED.flipHorizontal(!(i & 0x01));
delay(800);
}
}
void flipVertical(void)
{
for (int i = 0; i < 6; i++)
{
myOLED.flipVertical(!(i & 0x01));
delay(800);
}
}
void invert(void)
{
for (int i = 0; i < 6; i++)
{
myOLED.invert(!(i & 0x01));
delay(800);
}
}
// Use an array of testing functions, with a title, to run the tests
typedef void (*testFn)(void);
typedef struct _testRoutines
{
void (*testFn)(void);
const char *title;
} testRoutine;
static const testRoutine testFunctions[] = {
{scrollRight, "Right>"},
{scrollRightVertical, "^Right-Up>"},
{scrollLeft, "<Left"},
{scrollLeftVertical, "<Left-Up^"},
{scrollStop, "<STOP>"},
{flipHorizontal, "-Flip-Horz-"},
{flipVertical, "|Flip-Vert|"},
{invert, "**INVERT**"}};
void setup()
{
Serial.begin(115200);
Serial.println("Running OLED example");
Wire.begin();
// Initalize the OLED device and related graphics system
if (myOLED.begin() == false)
{
Serial.println("Device begin failed. Freezing...");
while (true)
;
}
Serial.println("Begin success");
yoffset = (myOLED.getHeight() - myOLED.getStringHeight("a")) / 2;
delay(1000);
}
void loop()
{
// Loop over the test table entries, write title and run test.
for (int i = 0; i < sizeof(testFunctions) / sizeof(testFunctions[0]); i++)
{
if (testFunctions[i].title)
{
myOLED.erase();
myOLED.text(3, yoffset, testFunctions[i].title);
myOLED.display();
}
testFunctions[i].testFn(); // run test
delay(3000);
}
}