New TFT Extension Library

UPDATE: 4/14/2014

Ok this update has the new polygon and drawStar functions, as well as a new version of the all the Triangle functions.

The polygon and drawStar functions need a single X,Y coordinate, the polygon function, also needs a number of sides(3 - 360) anything more and the function doesn’t work. You can also give it a color (still working on how to fill the polygon) and a degree if needed. The drawStar function needs a diameter, a color and a factor (1.0 - 4.0) which is preset to 2.0. This factor controls the thickness of the star. The higher the number, the thinner the star gets, and the factor will not go lower than 1.0 or higher than 4.0

Now with the triangle functions, you don’t need to specify a direct like “up, down ,left or right” and also give a degree. The new functions only need the X,Y coords, a base length and a degree. I did leave in the up, down, left and right as degrees, so up = 0 deg, left = 90 deg, down = 180, and right = 270. You can also use these as " up + 45" which is just 45 degrees, or “down - 27” which equals 153 deg.

myTFT.drawStar(160, 120, 30, WHITE);
myTFT.drawStar(160, 120, 30, WHITE, 3.0); // this star is thinner than the one above.

myTFT.Polygon(50, 50, 3, 20, BLUE); // X, Y, sides, diameter

myTFT.drawTriangle(160, 120, 50, up + 45);
myTFT.drawTriangle(160, 120, 50, right);
myTFT.drawTriangle(160, 120, 50, down - 27);

I am still working on being able to fill in the star and polygon shapes, but for now this should do. (40.2 KB)

I have three more functions on the way, two are already done and one i'm still working on. The two that are done are drawArc and TouchArc.

drawArc(int cx, int cy, int radius, int start, int stop, int thickness, byte R, byte G, byte B); Like my circle function, it needs a X/Y coordinate, a radius, and now it needs a start and stop angle, a thickness (will not exceed the radius value or below 0) and finally, a color.

TouchArc(int cx, int cy, int radius, int start, int stop, int thickness); This function returns a percentage of where you touch the arc from right to left. 0 - 100%

And the last function is a Slider, it can either be horizontal or vertical, and it too will return the percentage of it's level. It can be mapped to any size or thickness, and I must insist you use a stylist or something with a soft point.

HazardsMind: I am open to new function ideas if anyone has any. I will of course add your name or username to the functions description. ...

do you have - rounded_square(x,y,h,w, radius, color) // radius is of the rounded corners by default this is min(w ,h) /4; - moon(x, y, size, phase) // if you have stars you should have a moon - smiley(mood); // simplified - yellow circle with some basic lines. - text-balloon(position, size, pointer angle, text) - hourglass (position, size, percentage) - Greek alphabet and math symbols? - Currency symbols $ € - music bar & notes -> e.g. display MIDI -.. enough to keep you busy I think ;)

robtillaart: - smiley(mood); // simplified - yellow circle with some basic lines.

I've designed a manuscript with notes, however a smiley interface is not one I've thought of. Might inspire a chat program of sorts.

I can make the rounded_square, maybe the moon, smiley faces, text-balloon, hourglass and music bar + notes.

The Greek, math and currency symbols would be easy to make if I could get into the original character table, but I'll try.

Do you want to hourglass to flip over?

Added: Rounded_Square : DONE (with fill) Moon + phases : DONE (also added craters) Faces : DONE (9 types of eyes and 7 types of mouths. I also added preset combinations) HourGlass : DONE (EDIT: Capable from 1 second to about 1 year, give or take a few hours; Or until the millis function rolls over and screws up the time. And NON Blocking);

Related to HourGlass function.

Does anyone know how long it takes for the millis function to rollover?

Excellent work with your project! Would it be practical to have a "analog" style gauge function? I am thinking of round speedometers, or tachometers that start at zero and finish at a higher value. The user would enter a zero point and span. Then, enter the size and location of the gauge.

Thanks for your work!

HazardsMind: Related to HourGlass function.

Does anyone know how long it takes for the millis function to rollover?

49 d, 17 h, 2 m, 47 s, and 297 millis .

Ok, Great then the HourGlass function, will be accurate to that length of time.

Ok here is the current version of my library.

The speech bubble is a pain in the butt. I can get it to display text in the center just fine, but when I want to divide the text to use the whole bubble, that’s when things go wrong.

I will get it eventually. (51.1 KB)

@cyclegadget Yea, I can make that, in fact I think I already did, but I didn't make it into a library function.

I will add it to the list.


Functions added:
rounded_Square :: robtillaart
drawMoon :: robtillaart
smiley_Face :: robtillaart
HourGlass :: robtillaart
SpeechBubble :: robtillaart

drawGauge :: cyclegadget

My own new functions:
Triangle : Bare basic make-a-triangle function
fillPoly : Basically a fill triangle function
drawOvalArc : See the example sketch, MoonLightPark

I moved the variable Thickness next to radius in both TouchArc and drawArc.
Polygon and drawStar now are able to be filled

And I am still working on making the SpeechBubble have multiple lines of text.

If anyone has anymore ideas for functions they would like to add to the library, let me know and I will add them.

**Currently working on the Greek Font and symbols. (55.4 KB)

Apparently there was an issue with my ConnectFour game that I was unaware of. Here is the fixed version.
Sorry about that.

Added: I decided to make a Bluetooth chat sketch, with a decent looking keyboard and functionality, and so far the results are very promising. Right now it has all the lower case keys plus a working shift key which capitalizes the keys and stores them into a buffer array. I will add all the symbols [~!@#$%^&*()_+] too, but no F1 - F12 keys.

!!! The keyboard is done and working, and it is a new library function. : }

Connect_Four.ino (14.6 KB)


Keyboard functions and example sketch.

I tested the keyboard functions with RealTerm and works for portrait and landscape modes.
I may make it look better in appearance in the future, but that’s for another time.


ADDED: GreekFont. Drop inside UTFT folder
**If you look at the GreekFont’s .c file and you see almost everything as ?, don’t worry, it does the exact same thing on my end. For whatever reason, neither wordpad, notepad++, or MSword want to display the Greek symbols upon file entry. Sorry. (58.4 KB)

GreekFont.c (3.3 KB)

Update for my Connect Four game!

Players can now play over Bluetooth, and the computer’s diagonal block now works correctly. Also I made it so that the computer tries to win, thanks to the AISmartResponse function; The computer is now a rather good opponent.

The only thing I might add now, is a difficult setting and maybe some animations (show piece falling down into place instead of just appearing in place and have the pieces empty out of jig at the bottom).

Im thinking of new games to make, maybe Tetris :smiley:

I didn’t realize, the game was not attached, my bad.

Connect_Four.ino (18.1 KB)

Slight update with Keyboard functions. New Font added!

Put new font into UTFT folder.

Game: Don’t Block Me, is now able to be played in both landscape and portrait modes.
Just change this line #define Orientation LANDSCAPE to either LANDSCAPE or PORTRAIT, then upload to arduino.

Game: Connect_Four, now has falling animation and fixed “Host/Guest screen” (58.7 KB)

TRONFont.c (6.65 KB)

Don_t_Block_Me_.ino (5.09 KB)

Connect_Four.ino (18.4 KB)

HazardsMind, Thank you for all of your hard work! I tried your "Analog Gauge" example and a couple others but, I had problems compiling them. Here is the error message below for the Gauge example. Can you help fix it?

Arduino: 1.5.6-r2 (Windows 7), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

Build options changed, rebuilding all

C:\Users\name\Documents\Arduino\libraries\UTFT/UTFT.h: In member function 'void TFT_Extension::makeKeyboard()':
C:\Users\name\Documents\Arduino\libraries\UTFT/UTFT.h:171: error: 'void UTFT::printChar(byte, int, int)' is protected
C:\Users\name\Documents\Arduino\libraries\TFT_Extension\TFT_Extension.cpp:1914: error: within this context
C:\Users\name\Documents\Arduino\libraries\UTFT/UTFT.h: In member function 'void TFT_Extension::makeShiftKeys()':
C:\Users\name\Documents\Arduino\libraries\UTFT/UTFT.h:171: error: 'void UTFT::printChar(byte, int, int)' is protected
C:\Users\name\Documents\Arduino\libraries\TFT_Extension\TFT_Extension.cpp:1935: error: within this context
C:\Users\name\Documents\Arduino\libraries\UTFT/UTFT.h: In member function 'void TFT_Extension::makeCapsKeys()':
C:\Users\name\Documents\Arduino\libraries\UTFT/UTFT.h:171: error: 'void UTFT::printChar(byte, int, int)' is protected
C:\Users\name\Documents\Arduino\libraries\TFT_Extension\TFT_Extension.cpp:1950: error: within this context

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

I think you need to update your UTFT library. void printChar(byte c, int x, int y); should be under public: in the UTFT.h file but yours is saying it is under protected:

If you want, you can simply move the printChar function under the public access functions, save it, then it should work after that.

Thank you HazardsMind! I updated my UTFT library provided by Henning Karlson, and that fixed my problems with compiling your examples.

Something that my be helpful for other people using your examples would be this bit of commenting, and code that was provided with the UTFT library.

// Uncomment the next two lines for the Arduino 2009/UNO
//UTFT        myGLCD(ITDB24D,19,18,17,16);   // Remember to change the model parameter to suit your display module!
//UTouch      myTouch(15,10,14,9,8);

// Uncomment the next two lines for the Arduino Mega
UTFT        myGLCD(ITDB32S, 38,39,40,41);   // Remember to change the model parameter to suit your display module!
UTouch      myTouch(6,5,4,3,2);

Thank you for your work! It will really help me make some nice display screens!

I will include those. I also need to point out that some TFT LCD you buy online may appear to have the proper UTFT and Touch libraries, but in fact they are usually modified versions(fake) made for that particular TFT display. Mine just so happens to be one of those fake displays, so I am unable to use the real UTFT library, unless I buy a new display.

But never the less I found a way around that and made this library that works for both types of displays.