Skip to content

Commit 0518796

Browse files
committed
2 parents edbe0e7 + 050ee6c commit 0518796

File tree

7 files changed

+154
-133
lines changed

7 files changed

+154
-133
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Documentation
2626

2727
Products that use this Library
2828
---------------------------------
29-
* [SparkFun 1.8 inch TFT Breakout 128x160 (coming soon!)](https://www.sparkfun.com/products/15143)
29+
* [SparkFun 1.8 inch TFT Breakout 128x160](https://www.sparkfun.com/products/15143)
3030

3131
Version History
3232
---------------

examples/Example1_DisplayTest/Example1_DisplayTest.ino

+10-6
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,18 @@ ILI9163C_color_18_t defaultColor; // Global objects are used for default colors
3939

4040
void setup() {
4141
SERIAL_PORT.begin(9600);
42+
43+
//Uncomment this if you want to wait to println until the serial monitor is open.
44+
//while (!SERIAL_PORT); //Wait for Serial Monitor to Open
45+
4246
SERIAL_PORT.println("Example1 Display Test : SparkFun TFT LCD 1.8in Breakout");
4347

4448
myTFT.begin(DC_PIN, CS_PIN, PWM_PIN, SPI_PORT, SPI_SPEED);
4549
myTFT.clearDisplay();
4650

4751
myTFT.setTextCursor(0,0); // Sets the cursor relative to the current window, however the current (default) window is equivalent to the whole display. (0,0) is the upper left corner and (myTFT.xExt-1, myTFT.yExt-1) is the lower right
4852
myTFT.setCurrentWindowColorSequence((color_t)&defaultColor);
49-
53+
5054
uint16_t hue = HSV_HUE_MIN;
5155
while(hue <= HSV_HUE_MAX){
5256
myTFT.setTextCursor(0,0);
@@ -58,10 +62,10 @@ void setup() {
5862
void loop() {
5963
lineTest();
6064
delay(500);
61-
65+
6266
rectTest();
6367
delay(500);
64-
68+
6569
circleTest();
6670
for(uint8_t indi = 250; indi > 1; indi--){
6771
myTFT.setBacklight(indi); // Set the brightness of the backlight using PWM output
@@ -77,15 +81,15 @@ void loop() {
7781
void lineTest( void )
7882
{
7983
ILI9163C_color_18_t color;
80-
84+
8185
myTFT.clearDisplay();
8286

8387
color = myTFT.rgbTo18b( 255, 255, 255 );
8488
for(hd_hw_extent_t indi = 0; indi < myTFT.xExt; indi++)
8589
{
8690
myTFT.line(0,0,indi,myTFT.yExt-1,1,(color_t)&color);
8791
}
88-
92+
8993
color = myTFT.rgbTo18b( 255, 0, 0 );
9094
for(hd_hw_extent_t indi = 0; indi < myTFT.yExt; indi++)
9195
{
@@ -139,7 +143,7 @@ void circleTest( void )
139143
{
140144
myTFT.clearDisplay();
141145
ILI9163C_color_18_t color;
142-
146+
143147
for(uint8_t indi = 0; indi < (myTFT.xExt/2 - 1); indi++)
144148
{
145149
color = myTFT.hsvTo18b( (uint16_t)((double)(((double)HSV_HUE_MAX*indi)/((double)myTFT.xExt/2 - 1))), 255, 255 );

examples/Example2_HyperDisplayBasics/Example2_HyperDisplayBasics.ino

+21-17
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ This software is open source. Use it how you like, just don't hurt people.
2727
What is hyperdisplay?
2828
HD is an abstract C++ library for controlling 2D output devices by taking advantage of a common interface.
2929
30-
Despite many individual display technologies needing varying electrical interfaces to operate they nearly
31-
all can be controlled (conceptually) as long as you have the ability to set a particular pixel to an
30+
Despite many individual display technologies needing varying electrical interfaces to operate they nearly
31+
all can be controlled (conceptually) as long as you have the ability to set a particular pixel to an
3232
arbitrary color. Hyperdisplay "assumes" that this capability exists and then uses it to implement drawing
33-
functions, text, and many other capabilities in a standard, hardware-independent manner.
33+
functions, text, and many other capabilities in a standard, hardware-independent manner.
3434
*/
3535

3636
#define SERIAL_PORT Serial // Allows users to easily change target serial port (e.g. SAMD21's SerialUSB)
@@ -42,14 +42,18 @@ functions, text, and many other capabilities in a standard, hardware-independent
4242
#define SPI_SPEED 32000000 // Requests host uC to use the fastest possible SPI speed up to 32 MHz
4343

4444
KWH018ST01_4WSPI myTFT; // The KWH018ST01_4WSPI class is used for this breakout, and we will call our object myTFT
45-
// The class is derived from the hyperdisplay class, and so it has all the functionality of
45+
// The class is derived from the hyperdisplay class, and so it has all the functionality of
4646
// hyperdisplay plus a little more. In this example we will only focus on the functions that
4747
// come from hyperdisplay
4848

4949
ILI9163C_color_18_t defaultColor; // To use a default color it is best to make the variable global
5050

5151
void setup() {
5252
SERIAL_PORT.begin(9600);
53+
54+
//Uncomment this if you want to wait to println until the serial monitor is open.
55+
//while (!SERIAL_PORT); //Wait for Serial Monitor to Open
56+
5357
SERIAL_PORT.println("Example2 HyperDisplay Basics : SparkFun TFT LCD 1.8in Breakout");
5458

5559
myTFT.begin(DC_PIN, CS_PIN, PWM_PIN, SPI_PORT, SPI_SPEED); // This is a non-hyperdisplay function, but it is required to make the display work
@@ -61,7 +65,7 @@ void setup() {
6165
// Exploration of HyperDisplay abilities:
6266
/*
6367
The base layer of hyperdisplay only handles drawing functions:
64-
pixel
68+
pixel
6569
xline
6670
yline
6771
line
@@ -72,10 +76,10 @@ void setup() {
7276
fillWindow
7377
Each of these functions roughly follows a pattern for the arguments: (locations, options, color info)
7478
Also the location information of these functions is relative to a "window" - though the defualt window
75-
the entire display, so for basic applications there's no need to worry about it.
79+
the entire display, so for basic applications there's no need to worry about it.
7680
7781
Because HD can handle everything from monochrome OLEDs to full color TFTs it is up to the user to specify
78-
color information. HD uses the notion of color cycles - that is patterns of colors that can be repeated.
82+
color information. HD uses the notion of color cycles - that is patterns of colors that can be repeated.
7983
Every drawing function uses parameters called colorCycleLength and colorCycleOffset, which default to 1 and 0
8084
*/
8185

@@ -97,13 +101,13 @@ void setup() {
97101
pixelColor.r = 0xFF; // Set the r, g, and b values how you like
98102
pixelColor.g = 0;
99103
pixelColor.b = 0;
100-
101-
myTFT.clearDisplay(); // To be flexible the 'pixel' function needs to take a 'color_t' type
104+
105+
myTFT.clearDisplay(); // To be flexible the 'pixel' function needs to take a 'color_t' type
102106
myTFT.pixel(0,0, (color_t)&pixelColor); // so we cast the reference of our pixelColor to the color_t type
103107
delay(5000);
104108

105109
// Now let's do examples of the other HyperDipslay drawing functions using our color:
106-
myTFT.clearDisplay();
110+
myTFT.clearDisplay();
107111
myTFT.setTextCursor(0,0);
108112
myTFT.print("(X/Y)Line Example...");
109113
delay(1000);
@@ -119,7 +123,7 @@ void setup() {
119123
0x80, // blue
120124
};
121125

122-
myTFT.clearDisplay();
126+
myTFT.clearDisplay();
123127
myTFT.setTextCursor(0,0);
124128
myTFT.print("Rectangle Example...");
125129
delay(1000);
@@ -129,7 +133,7 @@ void setup() {
129133
delay(5000);
130134

131135

132-
myTFT.clearDisplay();
136+
myTFT.clearDisplay();
133137
myTFT.setTextCursor(0,0);
134138
myTFT.print("Circle Example...");
135139
delay(1000);
@@ -138,11 +142,11 @@ void setup() {
138142
myTFT.circle(64, 64, 24, true, (color_t)&innerRectColor);
139143
myTFT.circle(64, 64, 12, false, (color_t)&pixelColor);
140144
delay(5000);
141-
142145

143146

144-
// Now let's talk about the option to use a default color!
145-
myTFT.clearDisplay();
147+
148+
// Now let's talk about the option to use a default color!
149+
myTFT.clearDisplay();
146150
myTFT.setTextCursor(0,0);
147151
myTFT.print("Default Color Example..."); // Default color is used to print to the screen
148152
delay(1000);
@@ -151,8 +155,8 @@ void setup() {
151155
myTFT.pixel(5, 40); // Default color also can be used in place of a color in any drawing function
152156
myTFT.setTextCursor(0,0);
153157
myTFT.setCurrentWindowColorSequence((color_t)&innerRectColor); // You can change the current default color like this
154-
myTFT.print("Changing the default color changes the color of text and drawing functions!");
155-
myTFT.pixel(7, 40); // And as shown here the new default color is used for the next call to a drawing function
158+
myTFT.print("Changing the default color changes the color of text and drawing functions!");
159+
myTFT.pixel(7, 40); // And as shown here the new default color is used for the next call to a drawing function
156160
delay(20000);
157161

158162

examples/Example3_AdvancedHyperDisplay/Example3_AdvancedHyperDisplay.ino

+36-32
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,16 @@ This software is open source. Use it how you like, just don't hurt people.
3131
#define SPI_PORT SPI
3232
#define SPI_SPEED 32000000 // Requests host uC to use the fastest possible SPI speed up to 32 MHz
3333

34-
KWH018ST01_4WSPI myTFT;
34+
KWH018ST01_4WSPI myTFT;
3535

3636
ILI9163C_color_18_t defaultColor;
3737

3838
void setup() {
3939
SERIAL_PORT.begin(9600);
40+
41+
//Uncomment this if you want to wait to println until the serial monitor is open.
42+
//while (!SERIAL_PORT); //Wait for Serial Monitor to Open
43+
4044
SERIAL_PORT.println("Example3 Advanced HyperDisplay : SparkFun TFT LCD 1.8in Breakout");
4145

4246
myTFT.begin(DC_PIN, CS_PIN, PWM_PIN, SPI_PORT, SPI_SPEED); // This is a non-hyperdisplay function, but it is required to make the display work
@@ -49,22 +53,22 @@ void setup() {
4953
// Here are the function prototypes from the library -- we can break them down bit by bit
5054
/*
5155
void pixel(hd_extent_t x0, hd_extent_t y0, color_t data = NULL, hd_colors_t colorCycleLength = 1, hd_colors_t startColorOffset = 0);
52-
void xline(hd_extent_t x0, hd_extent_t y0, hd_extent_t len, color_t data = NULL, hd_colors_t colorCycleLength = 1, hd_colors_t startColorOffset = 0, bool goLeft = false);
56+
void xline(hd_extent_t x0, hd_extent_t y0, hd_extent_t len, color_t data = NULL, hd_colors_t colorCycleLength = 1, hd_colors_t startColorOffset = 0, bool goLeft = false);
5357
void yline(hd_extent_t x0, hd_extent_t y0, hd_extent_t len, color_t data = NULL, hd_colors_t colorCycleLength = 1, hd_colors_t startColorOffset = 0, bool goUp = false);
54-
void rectangle(hd_extent_t x0, hd_extent_t y0, hd_extent_t x1, hd_extent_t y1, bool filled = false, color_t data = NULL, hd_colors_t colorCycleLength = 1, hd_colors_t startColorOffset = 0, bool reverseGradient = false, bool gradientVertical = false);
55-
void fillFromArray(hd_extent_t x0, hd_extent_t y0, hd_extent_t x1, hd_extent_t y1, color_t data = NULL, hd_pixels_t numPixels = 0, bool Vh = false);
58+
void rectangle(hd_extent_t x0, hd_extent_t y0, hd_extent_t x1, hd_extent_t y1, bool filled = false, color_t data = NULL, hd_colors_t colorCycleLength = 1, hd_colors_t startColorOffset = 0, bool reverseGradient = false, bool gradientVertical = false);
59+
void fillFromArray(hd_extent_t x0, hd_extent_t y0, hd_extent_t x1, hd_extent_t y1, color_t data = NULL, hd_pixels_t numPixels = 0, bool Vh = false);
5660
void fillWindow(color_t color, hd_colors_t colorCycleLength = 1, hd_colors_t startColorOffset = 0);
57-
void line(hd_extent_t x0, hd_extent_t y0, hd_extent_t x1, hd_extent_t y1, uint16_t width = 1, color_t data = NULL, hd_colors_t colorCycleLength = 1, hd_colors_t startColorOffset = 0, bool reverseGradient = false);
61+
void line(hd_extent_t x0, hd_extent_t y0, hd_extent_t x1, hd_extent_t y1, uint16_t width = 1, color_t data = NULL, hd_colors_t colorCycleLength = 1, hd_colors_t startColorOffset = 0, bool reverseGradient = false);
5862
void polygon(hd_extent_t x[], hd_extent_t y[], uint8_t numSides, uint16_t width = 1, color_t data = NULL, hd_colors_t colorCycleLength = 1, hd_colors_t startColorOffset = 0, bool reverseGradient = false);
59-
void circle(hd_extent_t x0, hd_extent_t y0, hd_extent_t radius, bool filled = false, color_t data = NULL, hd_colors_t colorCycleLength = 1, hd_colors_t startColorOffset = 0, bool reverseGradient = false);
63+
void circle(hd_extent_t x0, hd_extent_t y0, hd_extent_t radius, bool filled = false, color_t data = NULL, hd_colors_t colorCycleLength = 1, hd_colors_t startColorOffset = 0, bool reverseGradient = false);
6064
*/
6165
// In every case the first arguments have to do with the geometry of the function and they are required
6266
// After that come arguments having to do with the color - or more appropriately the color cycle
63-
// - color_t data : this is a pointer to the color. The data that exists at this pointer will be assumed to be of the color type
67+
// - color_t data : this is a pointer to the color. The data that exists at this pointer will be assumed to be of the color type
6468
// that the display uses. This defaults to NULL in which case it will try to use a default color
6569
// - hd_colors_t colorCycleLength : this number tells how long the color cycle is - in other words it is a promise that this many
6670
// color objects exist consecutively after the pointer 'data.' If not specified this defaults to 1
67-
// - hd_colors_t startColorOffset : this number allows the color cycle to start part-way through the color cycle. If this number is greater
71+
// - hd_colors_t startColorOffset : this number allows the color cycle to start part-way through the color cycle. If this number is greater
6872
// than the color cycle length it is wrapped back around with a modulo operation. This value defaults to 0
6973
// Then finally there may be some additional options that are specific to each function. To change these you will need to explicitly state all other arguments
7074

@@ -84,10 +88,10 @@ void setup() {
8488
myTFT.line(2,12, 126,12, 4, (color_t)colorArray, CCLength, indi); // Notice that it is okay for startColorOffset to exceed colorCycleLength
8589
delay(20);
8690
}
87-
myTFT.clearDisplay();
91+
myTFT.clearDisplay();
8892

8993

90-
// Color cycles work in two ways for rectangles:
94+
// Color cycles work in two ways for rectangles:
9195
// For a non-filled rectangle the cycle goes around the perimeter, and you can reverse the direction. It always starts from the upper-left corner
9296
// For a filled rectangle the color cycle is used to create either a horizontal or vertical gradient, both of which can be reversed
9397
const uint8_t rectCCLength = 60;
@@ -98,26 +102,26 @@ void setup() {
98102
rectColorArray[indi].b = 0x00;
99103
}
100104
// Color cycles and options for rectangles:
101-
myTFT.rectangle(3, 3, 124, 156, false, (color_t)rectColorArray, rectCCLength, 0); // Makes a non-filled rectablge around the whole screen
105+
myTFT.rectangle(3, 3, 124, 156, false, (color_t)rectColorArray, rectCCLength, 0); // Makes a non-filled rectablge around the whole screen
102106
myTFT.rectangle(0, 0, 127, 159, false, (color_t)rectColorArray, rectCCLength, 0, true); // Makes a non-filled rectablge around the whole screen with the cycle going in the other direction
103107
myTFT.rectangle(6, 6, 60, 76, true, (color_t)rectColorArray, rectCCLength, 0); // Makes a filled rectangle that defaults to a non-reversed horizontal gradient (the color cycle is the gradient)
104108
myTFT.rectangle(68, 6, 121, 76, true, (color_t)rectColorArray, rectCCLength, 0, true); // Makes a filled rectangle with a horizontal gradient that is reversed
105109
myTFT.rectangle(6, 84, 60, 153, true, (color_t)rectColorArray, rectCCLength, 0, false, true); // Makes a filled rectangle with a non-reversed vertical gradient
106110
myTFT.rectangle(68, 84, 121, 153, true, (color_t)rectColorArray, rectCCLength, 0, true, true); // Makes a filled rectangle with a vertical gradient that is reversed
107111
delay(5000);
108-
myTFT.clearDisplay();
112+
myTFT.clearDisplay();
109113

110114

111115

112116
// Another HyperDisplay feature not discussed in Example2 is the "polygon" function(s).
113-
// Polygon will automatically draw several connected lines when given the coordinates in a list.
117+
// Polygon will automatically draw several connected lines when given the coordinates in a list.
114118
// The main advantages are simplicity and the fact that a color cycle can run uninterrupted through the whole polygon.
115-
hd_extent_t xCoords[] = {64, 127, 0, 127, 0};
119+
hd_extent_t xCoords[] = {64, 127, 0, 127, 0};
116120
hd_extent_t yCoords[] = {24, 120, 60, 60, 120};
117121
if(sizeof(xCoords) != sizeof(yCoords)){
118122
SERIAL_PORT.println("Coordinate array dimensions mismatch. Please make xCoords and yCoords have the same number of elements. Freezing");
119123
while(1){};
120-
}
124+
}
121125
myTFT.polygon(xCoords, yCoords, sizeof(xCoords)/sizeof(hd_extent_t), 1, (color_t)rectColorArray, rectCCLength, 0, false); // You can choose the width (3 here) and whether or not to reverse the gradient direction too
122126
delay(5000);
123127
myTFT.clearDisplay();
@@ -144,15 +148,15 @@ void setup() {
144148
color_t data; // A pointer to pixel data that is specific to the window. Can be left as NULL
145149
hd_pixels_t numPixels; // The number of pixel types that data points to
146150
bool dynamic; // Indicator if the current buffer memory was dynamically allocated - so that it can be disposed of automatically
147-
}wind_info_t; // Window infomation structure for placing objects on the display
151+
}wind_info_t; // Window infomation structure for placing objects on the display
148152
*/
149153
// You'll notice that the window structure handles min/max extent values, current cursor values, reset cursor values, character info, and color cycle info
150154

151-
// In previous examples we never mentioned windows and that's OK because the default window covers the entire screen.
155+
// In previous examples we never mentioned windows and that's OK because the default window covers the entire screen.
152156
// Now we will do a few demos with windows...
153157

154158
wind_info_t wind1, wind2, wind3; // Create several window objects
155-
ILI9163C_color_18_t color1, color2, color3;
159+
ILI9163C_color_18_t color1, color2, color3;
156160

157161
// Initialize the windows to defualt settings (this is a pretty important step unless you are extra careful to manually initialize each and every paramter)
158162
myTFT.setWindowDefaults(&wind1);
@@ -162,17 +166,17 @@ void setup() {
162166
color1.r = 0xFF; // Set the colors to red, green, and blue respectively
163167
color1.g = 0x00;
164168
color1.b = 0x00;
165-
169+
166170
color2.r = 0x00;
167171
color2.g = 0xFF;
168172
color2.b = 0x00;
169-
170-
color3.r = 0x00;
173+
174+
color3.r = 0x00;
171175
color3.g = 0x00;
172176
color3.b = 0xFF;
173177

174178
// Now we will set up the boundaries of the windows, the cursor locations, and their default colors
175-
wind1.xMin = 0;
179+
wind1.xMin = 0;
176180
wind1.yMin = 0;
177181
wind1.xMax = 62;
178182
wind1.yMax = 78;
@@ -182,9 +186,9 @@ void setup() {
182186
wind1.yReset = 1;
183187
wind1.currentSequenceData = (color_t)&color1;
184188
wind1.currentColorCycleLength = 1;
185-
wind1.currentColorOffset = 0;
189+
wind1.currentColorOffset = 0;
186190

187-
wind2.xMin = 65;
191+
wind2.xMin = 65;
188192
wind2.yMin = 0;
189193
wind2.xMax = 127;
190194
wind2.yMax = 78;
@@ -194,9 +198,9 @@ void setup() {
194198
wind2.yReset = 15;
195199
wind2.currentSequenceData = (color_t)&color2;
196200
wind2.currentColorCycleLength = 1;
197-
wind2.currentColorOffset = 0;
198-
199-
wind3.xMin = 0;
201+
wind2.currentColorOffset = 0;
202+
203+
wind3.xMin = 0;
200204
wind3.yMin = 81;
201205
wind3.xMax = 127;
202206
wind3.yMax = 159;
@@ -206,9 +210,9 @@ void setup() {
206210
wind3.yReset = 1;
207211
wind3.currentSequenceData = (color_t)&color3;
208212
wind3.currentColorCycleLength = 1;
209-
wind3.currentColorOffset = 0;
210-
211-
// All hyperdisplay drawing functions are applied to the current window, and the coordinates are with respect to the window.
213+
wind3.currentColorOffset = 0;
214+
215+
// All hyperdisplay drawing functions are applied to the current window, and the coordinates are with respect to the window.
212216
// To demonstrate this we will use the same exact drawing function to draw in each of the three windows, each with to unique effect
213217
wind_info_t* windowPointers[] = {&wind1, &wind2, &wind3};
214218
for(uint8_t indi = 0; indi < 3; indi++){
@@ -224,15 +228,15 @@ void setup() {
224228
}
225229
delay(5000);
226230

227-
// And lastly, the printing functions are impacted by windows.
231+
// And lastly, the printing functions are impacted by windows.
228232
for(uint8_t indi = 0; indi < 3; indi++){
229233
myTFT.pCurrentWindow = windowPointers[indi]; // Set the current window
230234
myTFT.setCurrentWindowColorSequence((color_t)&defaultColor); // Change each window's color to the white value we defined at the beginning
231235
myTFT.println("You see, each window handles printed text on its own!");
232236

233237
myTFT.print("Done!");
234238
}
235-
239+
236240
SERIAL_PORT.println("Done!");
237241
myTFT.println("\n\nDone!");
238242
}

0 commit comments

Comments
 (0)