Please updated library in last REPLY.
I originally made this library for my own uses, but I feel it should be shared. It works with Henning Karlsen's UTFT and UTouch libraries and it also works with his older ITDB02 libraries. "ITDB02_Graph16 and ITDB02_Touch"
PLEASE NOTE, I am still adding functions to this library (95% Done), mostly colors and functions that allow the user to choose there colors for certain functions like the drawTriangle function.
Right now I only have a 3.2 TFT Lcd that uses the older ITDB02 libraries, so all the examples will be set for those libraries, however, it does compile with the UTFT and UTouch examples.
One comment: The implementation does NOT go in the header file. Include (accidentally) that library twice, and you'll have all kinds of error messages that are hard to decipher.
double DIR = dir * 0.01745 + 1.57;
I hate magic numbers. You may know that they mean, but will everyone?
Ok, I changed
DIR = dir * 0.01745 + 1.57; to
DIR = dir * RAD_TO_DEG + HALF_PI;Better yet:
double DIR = dir * RAD_TO_DEG;
Cx = x1 + sin(DIR + deg * RAD_TO_DEG + PI) * rad;
.
.
.
Whats is wrong with the implementation? It seems to work just fine.
What would be the better way? Make a .cpp file?
Whats is wrong with the implementation? It seems to work just fine.
As long as you are careful to only include it once in the whole program. Can you guarantee that your users will do that?
What would be the better way? Make a .cpp file?
Exactly.
Ok, I changed DIR = dir * 0.01745 + 1.57; to DIR = dir * RAD_TO_DEG + HALF_PI;
Now, that makes sense.
Can you guarantee that your users will do that?
No, not at all. But if (Big if) they do everything else fine, then the worst they will get is this:
CirclePad:14: error: redefinition of 'TFT_Extension<ITDB02, ITDB02_Touch> myTFT'
CirclePad:13: error: 'TFT_Extension<ITDB02, ITDB02_Touch> myTFT' previously declared here
However it would help greatly if the Arduino software had visible line numbers on the side.
What would be the better way? Make a .cpp file?
Exactly.
By making a cpp file, I would need to include the UTFT and UTouch libraries, as well as the older ITDB02 libraries, right? What about if someone doesn't have the older libraries, the compiler will want to know where they are.
I'll figure it out.
@PaulS
Is there anyway I can make the precompiler detect if someone actually has the UTFT or UTouch libraries and then have the precompiler determine what lines to enable for the library to work?
Is there anyway I can make the precompiler detect if someone actually has the UTFT or UTouch libraries and then have the precompiler determine what lines to enable for the library to work?
Yes & no, depends on where its used in the library.
If you remember back to a previous post I helped you with; the method I used there was to detect the libraries and replace functionality. Remember this snippet:
struct MissingType{};
#ifdef LiquidCrystal_I2C_h
typedef LiquidCrystal_I2C LCDTYPE;
#else
typedef MissingType LCDTYPE;
#endif
This method allows you to keep all your missing class stuff in one place, which would suit a well built template and not need to be modified at all. An alternative is to use:
#ifdef LiquidCrystal_I2C_h
#define USING_CLASS
#endif
But everywhere the class is used, you need to wrap its code in preprocessor tags to allow or prevent it from compiling:
#ifdef USING_CLASS
//Class specific code.
#endif
Ah, ok I forgot about that. Thanks again Pyro.
Update: I added a new function, TextButton, and for right now, it will display text in the center of the button (the outline of the button still needs to be drawn separately) and you can still use it as a normal button. I am still working on the library and if I can get the TextButton function to work properly, I will do the same to the rest of the buttons.
I also added a wall ball game.
Library updated. Added Connect Four game.
Note: I'm currently working on the AI for the connect four game and as of this version, the computer is really dumb. If you look at the function to play against the computer, you'll see its just a few random functions and nothing else. So I am working on making it a bit more of a challenge, and so far it is going good.
After I get the AI to work, I am going to make the game wireless. Maybe not WiFi right now, because I don't have a WiFi module, but it will definitely be Bluetooth.
OK I got a nice little update on the library, I added quite a few new functions which may look confusing to use, but I provided example sketches on how to use them. I also a library description (.docx), hopefully it will clear up any questions.
New Functions:
TouchButton_Draw
LatchButton_Draw
TouchCircle_Draw
LatchCircle_Draw
TouchTriangle_Draw
LatchTriangle
LatchTriangle_Draw
SetTouchButtonColors
SetTouchCircleColors
SetLatchButtonColors
SetLatchCircleColors
SetTouchTriangleColors
SetLatchTriangleColors
The Connect Four game is nearly complete, I just need to fix the computers diagonal blocking algorithm and make it bluetooth capable.
I am still adding things to the library but at the length it is right now (+50 functions), there is still work to be done before I consider it complete.
There are a couple of sketches I provided that are still set to the old libraries but its not difficult to change them to the newer ones.
Try it out.
do you have some test program to see the performance - footprint of the lib?
Hello I like your extension but I did reorganize your filestructure to the Default Arduino file structure so examples work right after you have copied the new lib into the libraries. File attached.
@robtillaart Not at the moment no. Actually what would be the best way to do that?
@Jeroi Thanks, I know the filing structure is bad, I didn't think anyone would mind it, but I will change it.
you could simply write a small sketch as a sample program that measures the time for every function. And yes some depend on the params e.g. fill square will be slower for large squares but the example sketch will run the same test for every display.
Radio button time track, 1 group of both types with 4 buttons each
#include <ITDB02_Graph16.h>
#include <ITDB02_Touch.h>
#include <TFT_Extension_old.h>
#include <math.h>
// Declare which fonts we will be using
extern uint8_t SmallFont[];
//
//myGLCD(RS,WR,CS,RST,ALE,mode);
ITDB02 myGLCD(A1,A2,A0,A3,A5,ITDB32S);
//myTouch(TCLK,TCS,DIN,DOUT,IRQ);
ITDB02_Touch myTouch(13,10,11,12,A4);
TFT_Extension_old myTFT(&myGLCD, &myTouch, LANDSCAPE);
int cx, cy;
unsigned long timeStart, Total, timeCollect[9];
char * functs[11] = {
"Setup TRB: ", "Setup TRCB: ", "Set RB colors: ", "Set RCB colors: ","1x RadioButton: ",
"4x RadioButtons: ","1x RadioCircleButton: ",
"4x RadioCircleButton: ", "Total Time: "};
void setup()
{
myGLCD.InitLCD(LANDSCAPE);
myGLCD.clrScr();
myGLCD.setFont(SmallFont);
myTouch.InitTouch(LANDSCAPE);
myTouch.setPrecision(PREC_LOW);
for(int line = 0; line <= 239; line++)
{
myGLCD.setColor(0, 0, line);//text color White
myGLCD.drawLine(0, line, 319, line);
}
Serial1.begin(9600);
startup();
getButton();
myGLCD.clrScr();
for(byte idx = 0; idx < 8; idx++)
{
myGLCD.print(functs[idx], 0, idx * 20);
myGLCD.printNumF(timeCollect[idx], 200, idx * 20 );
Total += timeCollect[idx] / 1000.00;
myGLCD.printNumF(Total,3, 200, 200 );
}
}
void loop() {}
void startup()
{
myGLCD.setColor(255, 0, 0);//red box fill
myGLCD.fillRect(0, 0, 319, 13);//text box
myGLCD.setColor(255, 255, 255);//text color White
myGLCD.setBackColor(255, 0, 0);//background of text red
myGLCD.drawLine(0, 14, 319, 14);
myGLCD.print("ARDUINO RADIOBUTTONS", CENTER, 1);
myGLCD.setBackColor(0, 0, 0);
myGLCD.print("Touch screen to start", CENTER, 119);
for(int line = 0; line <= 239; line++)
{
myGLCD.setColor(0, 0, line);//text color White
myGLCD.drawLine(0, line, 319, line);
}
uint8_t nums[1] = {4}; // 4 buttons per group
timeStart = micros();
myTFT.TotalRadioButtons(nums,1);
timeCollect[0] = micros() - timeStart;
timeStart = micros();
myTFT.TotalRadioCircleButtons(nums,1);
timeCollect[1] = micros() - timeStart;
timeStart = micros();
myTFT.SetAll_RB_Outer_Color(BLACK);
myTFT.SetAll_RB_Toggled_Color(GREEN);
myTFT.SetAll_RB_Untoggled_Color(YELLOW);
timeCollect[2] = micros() - timeStart;
timeStart = micros();
myTFT.SetAll_RCB_Outer_Color(PURPLE);
myTFT.SetAll_RCB_Toggled_Color(BLUE);
myTFT.SetAll_RCB_Untoggled_Color(RED);
timeCollect[3] = micros() - timeStart;
}
void getButton()
{
timeStart = micros();
myTFT.RadioButton(10,10,50,50,0,0);
timeCollect[4] = micros() - timeStart;
myTFT.RadioButton(10,60,50,100,1,0 );
myTFT.RadioButton(10,110,50,150,2,0 );
myTFT.RadioButton(10,160,50,200,3,0 );
timeCollect[5] = micros() - timeStart;
//=================================================
timeStart = micros();
myTFT.RadioCircleButton(80,30,20,0,0 );
timeCollect[6] = micros() - timeStart;
myTFT.RadioCircleButton(80,80,20,1,0 );
myTFT.RadioCircleButton(80,130,20,2,0 );
myTFT.RadioCircleButton(80,180,20,3,0 );
timeCollect[7] = micros() - timeStart;
}
Output: Time in milliseconds
Setup TRB: 0.003
Setup TRCB: 0.007
Set RB colors: 0.027
Set RCB colors: 0.031
1x RadioButton: 66.895
4x RadioButton: 267.587
1x RadioCircleButton: 451.563
4x RadioCircleButton: 1806.251
Total Time: 2589.999
Both types of latching buttons.
#include <ITDB02_Graph16.h>
#include <ITDB02_Touch.h>
#include <TFT_Extension_old.h>
#include <math.h>
// Declare which fonts we will be using
extern uint8_t SmallFont[];
//myGLCD(RS,WR,CS,RST,ALE,mode);
ITDB02 myGLCD(A1,A2,A0,A3,A5,ITDB32S);
//myTouch(TCLK,TCS,DIN,DOUT,IRQ);
ITDB02_Touch myTouch(13,10,11,12,A4);
TFT_Extension_old myTFT(&myGLCD, &myTouch, LANDSCAPE);
unsigned long timeStart, timeCollect[9];
char * functs[11] = {
"Set TC color: ", "Setup LC color: ", "Set TB color: ", "Set LB color: ","TC_Draw: ",
"LC_Draw: ","TB_Draw: ","LB_Draw: ", "Total Time: "};
boolean last = LOW, latch = false;
void setup()
{
myGLCD.InitLCD(LANDSCAPE);
myGLCD.clrScr();
myGLCD.setFont(SmallFont);
myTouch.InitTouch(LANDSCAPE);
myTouch.setPrecision(PREC_LOW);
Serial1.begin(115200);
startup();
}
void loop() {}
void startup()
{
myGLCD.setColor(255, 0, 0);//red box fill
myGLCD.fillRect(0, 0, 319, 13);//text box
myGLCD.setColor(255, 255, 255);//text color White
myGLCD.setBackColor(255, 0, 0);//background of text red
myGLCD.drawLine(0, 14, 319, 14);
myGLCD.print("LatchButtons", CENTER, 1);
myGLCD.setBackColor(0, 0, 0);
myGLCD.print("Touch screen to start", CENTER, 119);
myGLCD.clrScr();
myGLCD.print("Latches", CENTER, 50);
myGLCD.print("Buttons", CENTER, 170);
timeStart = micros();
myTFT.SetTouchCircleColors(0, ORANGE, PURPLE, FILL); // ID number, Pressed Color, Released Color, FILL/NOFILL)
timeCollect[0] = micros() - timeStart;
timeStart = micros();
myTFT.SetLatchCircleColors(1, WHITE, CYAN, FILL); // ID number, Latched Color, UnLatched Color, FILL/NOFILL)
timeCollect[1] = micros() - timeStart;
timeStart = micros();
myTFT.SetTouchButtonColors(0, GREEN, RED, FILL, ROUNDED); // ID number, Pressed Color, Released Color, FILL/NOFILL,ROUNDED/NOTROUNDED)
timeCollect[2] = micros() - timeStart;
timeStart = micros();
myTFT.SetLatchButtonColors(1, BLUE, YELLOW, FILL, ROUNDED); // ID number, Latched Color, UnLatched Color, FILL/NOFILL, ROUNDED/NOTROUNDED)
timeCollect[3] = micros() - timeStart;
getButton();
myGLCD.clrScr();
for(byte idx = 0; idx < 9; idx++)
{
myGLCD.print(functs[idx], 0, idx * 20);
myGLCD.printNumF(float(timeCollect[idx]) / 1000.00,3, 200, idx * 20 );
}
}
void getButton()
{
timeStart = micros();
myTFT.TouchCircle_Draw(55,180,50,0); // (x,y,radius, ID number)
timeCollect[4] = micros() - timeStart;
timeStart = micros();
myTFT.LatchCircle_Draw(265,55,50,1); // (x,y,radius, ID number)
timeCollect[5] = micros() - timeStart;
timeStart = micros();
myTFT.TouchButton_Draw(220,135,310,225,0);// (x1,y1,x2,y2, ID number)
timeCollect[6] = micros() - timeStart;
timeStart = micros();
myTFT.LatchButton_Draw(10,10,100,100,1);// (x1,y1,x2,y2, ID number)
timeCollect[7] = micros() - timeStart;
timeCollect[8] = micros() - timeCollect[0];
}
Output time in milliseconds
Set TC color: 0.011
Setup LC color: 0.007
Set TB color: 0.011
Set LB color: 0.011
TC_Draw: 1795.851
LC_Draw: 1795.851
TB_Draw: 167.507
LB_Draw: 167.515
Total Time: 3923.999
Both types of triangles:
#include <ITDB02_Graph16.h>
#include <ITDB02_Touch.h>
#include <TFT_Extension_old.h>
#include <math.h>
// Declare which fonts we will be using
extern uint8_t SmallFont[];
//myGLCD(RS,WR,CS,RST,ALE,mode);
ITDB02 myGLCD(A1,A2,A0,A3,A5,ITDB32S);
//myTouch(TCLK,TCS,DIN,DOUT,IRQ);
ITDB02_Touch myTouch(13,10,11,12,A4);
TFT_Extension_old myTFT(&myGLCD, &myTouch, LANDSCAPE);
unsigned long timeStart, timeCollect[5];
char * functs[11] = {
"Set TT color: ", "Setup LT color: ", "TT_Draw: ",
"LT_Draw: ", "Total Time: "};
void setup()
{
myGLCD.InitLCD(LANDSCAPE);
myGLCD.clrScr();
myGLCD.setFont(SmallFont);
myTouch.InitTouch(LANDSCAPE);
myTouch.setPrecision(PREC_LOW);
Serial1.begin(115200);
startup();
}
void loop() {}
void startup()
{
myGLCD.setColor(255, 0, 0);//red box fill
myGLCD.fillRect(0, 0, 319, 13);//text box
myGLCD.setColor(255, 255, 255);//text color White
myGLCD.setBackColor(255, 0, 0);//background of text red
myGLCD.drawLine(0, 14, 319, 14);
myGLCD.print("LatchButtons", CENTER, 1);
myGLCD.setBackColor(0, 0, 0);
myGLCD.print("Touch screen to start", CENTER, 119);
myGLCD.clrScr();
myGLCD.print("Latches", CENTER, 50);
myGLCD.print("Buttons", CENTER, 170);
timeStart = micros();
myTFT.SetTouchTriangleColors(0, ORANGE, PURPLE, FILL); // ID number, Pressed Color, Released Color, FILL/NOFILL)
timeCollect[0] = micros() - timeStart;
timeStart = micros();
myTFT.SetLatchTriangleColors(1, WHITE, CYAN, FILL); // ID number, Latched Color, UnLatched Color, FILL/NOFILL)
timeCollect[1] = micros() - timeStart;
getButton();
myGLCD.clrScr();
for(byte idx = 0; idx < 5; idx++)
{
myGLCD.print(functs[idx], 0, idx * 20);
myGLCD.printNumF(float(timeCollect[idx]) / 1000.00,3, 200, idx * 20 );
}
}
void getButton()
{
timeStart = micros();
myTFT.TouchTriangle_Draw(55,180,50,up, 0, 0); // (x,y,radius, ID number)
timeCollect[2] = micros() - timeStart;
timeStart = micros();
myTFT.LatchTriangle_Draw(265,55,50,up, 0, 1); // (x,y,radius, ID number)
timeCollect[3] = micros() - timeStart;
timeCollect[4] = micros() - timeCollect[0];
}
Output:
Set TT color: 0.007
Set LT color: 0.011
TT_Draw: 419.235
LT_Draw: 417.835
Total Time: 838.088?
Here are the times for the radio button color functions.
#include <ITDB02_Graph16.h>
#include <ITDB02_Touch.h>
#include <TFT_Extension_old.h>
#include <math.h>
// Declare which fonts we will be using
extern uint8_t SmallFont[];
//myGLCD(RS,WR,CS,RST,ALE,mode);
ITDB02 myGLCD(A1,A2,A0,A3,A5,ITDB32S);
//myTouch(TCLK,TCS,DIN,DOUT,IRQ);
ITDB02_Touch myTouch(13,10,11,12,A4);
TFT_Extension_old myTFT(&myGLCD, &myTouch, LANDSCAPE);
unsigned long timeStart, timeCollect[13];
char * functs[13] = {
"Set RBO color: ", "Set RCBO color: ", "Set RBT color: ", "Set RCBT color: ",
"Set RBUT color: ", "Set RCBUT color: ", "Set RBO_BG color: ", "Set RCBO_BG color: ",
"Set RBT_BG color: ","Set RCBT_BG color: ", "Set RBUT_BG color: ","Set RCBUT_BG color: ",
"Total Time: "};
void setup()
{
myGLCD.InitLCD(LANDSCAPE);
myGLCD.clrScr();
myGLCD.setFont(SmallFont);
myTouch.InitTouch(LANDSCAPE);
myTouch.setPrecision(PREC_LOW);
Serial1.begin(115200);
startup();
}
void loop() {
}
void startup()
{
myGLCD.setColor(255, 0, 0);//red box fill
myGLCD.fillRect(0, 0, 319, 13);//text box
myGLCD.setColor(255, 255, 255);//text color White
myGLCD.setBackColor(255, 0, 0);//background of text red
myGLCD.drawLine(0, 14, 319, 14);
myGLCD.print("LatchButtons", CENTER, 1);
myGLCD.setBackColor(0, 0, 0);
myGLCD.print("Touch screen to start", CENTER, 119);
myGLCD.clrScr();
myGLCD.print("Latches", CENTER, 50);
myGLCD.print("Buttons", CENTER, 170);
timeStart = micros();
myTFT.RB_Outer_Color(0,1,WHITE);
timeCollect[0] = micros() - timeStart;
timeStart = micros();
myTFT.RCB_Outer_Color(0,1,WHITE);
timeCollect[1] = micros() - timeStart;
timeStart = micros();
myTFT.RB_Toggled_Color(0,1,WHITE);
timeCollect[2] = micros() - timeStart;
timeStart = micros();
myTFT.RCB_Toggled_Color(0,1,WHITE);
timeCollect[3] = micros() - timeStart;
timeStart = micros();
myTFT.RB_Untoggled_Color(0,1,WHITE);
timeCollect[4] = micros() - timeStart;
timeStart = micros();
myTFT.RCB_Untoggled_Color(0,1,WHITE);
timeCollect[5] = micros() - timeStart;
timeStart = micros();
myTFT.RB_Outer_Color_By_Group(1, GREEN);
timeCollect[6] = micros() - timeStart;
timeStart = micros();
myTFT.RCB_Outer_Color_By_Group(1, GREEN);
timeCollect[7] = micros() - timeStart;
timeStart = micros();
myTFT.RB_Toggled_Color_By_Group(1, GREEN);
timeCollect[8] = micros() - timeStart;
timeStart = micros();
myTFT.RCB_Toggled_Color_By_Group(1, GREEN);
timeCollect[9] = micros() - timeStart;
timeStart = micros();
myTFT.RB_Untoggled_Color_By_Group(1, GREEN);
timeCollect[10] = micros() - timeStart;
timeStart = micros();
myTFT.RCB_Untoggled_Color_By_Group(1, GREEN);
timeCollect[11] = micros() - timeStart;
timeCollect[12] = micros() - timeCollect[0];
myGLCD.clrScr();
for(byte idx = 0; idx < 13; idx++)
{
myGLCD.print(functs[idx], 0, idx * 16);
myGLCD.printNumF((float(timeCollect[idx]) / 1000.00),6, 200, idx * 16 );
}
}
Output:
Set RBO color: .00799
Set RCBO color: 0.00799
Set RBT color: 0.00799
Set RCBT color: 0.00799
Set RBUT color: 0.00799
Set RCBUT color: 0.00799
Set RBO_BG color: 0.00399
Set RCBO_BG color: 0.00799
Set RBT_BG color: 0.00399
Set RCBT_BG color: 0.00399
Set RBUT_BG color: 0.00799
Set RCBUT_BG color: 0.00399
Total Time: 0.07988
Small update, I changed TouchDelay to TouchDelayButton and added two new functions, TouchDelayCircle and TouchDelayTriangle.
I'm still working on the TextButton function, I am able to display text in the center with no problem, but I am trying to make the button be able to rotate (Still no problem). However, getting the text to rotate and still stay centered is proving to be a bit more challenging then expected. I will hopefully get that function working soon.
EDIT: There was a slight hiccup with the Portrait vs Landscape modes. Its fixed now.
UPDATE:
Both types of radio buttons now are able to have text in the center of them. Please note that the text will NOT be cutoff or the buttons size will NOT be altered if the text is larger than the button.
Newest version as of 4/11/2014
I am open to new function ideas if anyone has any. I will of course add your name or username to the functions description.
I am currently working on a star function and I should be done with it soon. As well as a polygon function which will allow the user to enter a number 3 - 10, and it will make the shape with the given sides. Filled in color may be difficult so for now it will just be unfilled.
Added: I finished both of them. They will be in the next update.
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.
Example:
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.
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.
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 ;)
- 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!
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.
@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.
UPDATE:
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.
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. : }
UPDATE
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.
Enjoy.
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.
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 :D
I didn't realize, the game was not attached, my bad.
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.
Added:
Game: Connect_Four, now has falling animation and fixed "Host/Guest screen"
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.
New game: Missile Bomber
Objective: destroy the incoming missiles and do NOT let them fall to the ground. Each missile is enough to wipe out an entire city, and if all 20 cities are destroyed, game over.
To destroy a missile, touch the center of them. 5 points for blowing up a missile, and 50 points triggers an additional missile. (6 max)
(Please keep in mind that an Arduino is not meant to display fast moving objects, so it will slow down.)
If anyone has a Due, let me know if it is any better. A small video would be helpful.
this is really help full for the draw gauge function thanks, is it possible to to draw more than one gauge?
I could make it so you could have more than one guage, let me modify the library.
if you wouldn't mind doing that that would be fantastic.
edit: also the HorSlider and VertSlider functions can they be used as a display? for instance analogRead(A0) map the values from 0-100 then use those as a display?
edit: also the HorSlider and VertSlider functions can they be used as a display? for instance analogRead(A0) map the values from 0-100 then use those as a display?
? What kind of display? They return 0-100 as a percent, so what else do you have in mind?
Updated library with new Gauges (10 Max)
Also all _Draw functions, (TouchButton_Draw, LatchCircle_Draw, TouchTriangle_Draw. . . etc) are now able to have centered text, they don't limit the text to the size of the "button", sorry too much code for that.
See the Latching_Buttons example.Question for everyone else. The library is kinda getting out of hand with all the structs, so if anyone has a better alternative, please share it. At first I was thinking of making everything into individual classes, but then everyone would need to drastically modify there sketches to use them. So if anyone has any ideas, please share and I will see what I can do.
ok im pulling data from a megasquirt ecu via serial, i trying to make a display to show various information from the engine sensors connected to that, for instance using the slider like a bar graph to display throttle the throttle.
Oh ok, so the other way around, instead of being a slider, you want a bar graph. Yea I can do that.
Ah that would rock, just tried your update and its working good tried with 4 gauges on the screen, had them all reading from a 10k pot all working good thanks. i did try it before with just one gauge and it worked on pulling the data via serial and displaying it on the gauge as well
Library is updated with new functions, HorBarGraph and VertBarGraph. Go back to previous post and re-download.
Look at Horizontal_BarGraph example to see how it is used.
I also added your username to the .h file.
oh got it that rocks, with those additions gives me just what i need to continue with my project.
been playing about with this some more, i'm using a switch case from a push button input to change between 3 different pages i want it to draw that works, first page just basic prints to the screen of the sensor readings, push button then page 2 so far i'm using drawgauge to draw 2 gauges one for engine rpm and the second for throttle 0-100% they work its a bit slow drawing them at first but the needle movements are quick enough after the back ground has drawn to the screen not to much of a biggie, then page3 will be some bar graphs ect not got that far yet though. the issue im having if you cycle from page 1,2,3 back to 1 then the second time on to page 2 the backgrounds don't get drawn only the needles part of the gauges.
Gromgsxr,
Would you mind sharing some of your switch case code? I am wanting to learn how to put the buttons and gauges to use but, I haven't figured it out yet.
Ok, I can make a quick function to allow you to repaint the gauge.
Added:
Function: ResetGauge( byte _ID ), This should go in the next and previous pages of the gauge. So if your gauges are on page 2, then this function needs to be in pages 1 and 3. So when you go back to page 2, the gauge will be repainted.
Library added below.
wicked il give that a go and report back thanks again, this is a basic striped down version of how i'm drawing the pages.
#include <UTFT.h>
#include <UTouch.h>
#include <memsaving.h>
#include <TFT_Extension.h>
extern uint8_t BigFont[];
UTFT myGLCD(SSD1289,38,39,40,41);
UTouch myTouch(6,5,4,3,2);
TFT_Extension myTFT(&myGLCD, &myTouch, LANDSCAPE);
const int buttonPin = A1; // the pin that the pushbutton is attached to
int buttonPushCounter = 0; // counter for the number of button presses
int ButtonState = 0; // current state of the button
int lastState = 0; // previous state of the button
void page1(){
myGLCD.setFont(BigFont);
myGLCD.setColor(255, 0, 0);
myGLCD.print(" page 1 ",CENTER, 80);
}
void page2(){
myGLCD.setFont(BigFont);
myGLCD.setColor(0, 255, 0);
myGLCD.print(" page 2 ",CENTER, 120);
}
void page3(){
myGLCD.setFont(BigFont);
myGLCD.setColor(0, 0, 255);
myGLCD.print(" page 3 ",CENTER, 150);
}
void setup() {
pinMode(buttonPin, INPUT);
myGLCD.InitLCD();
myGLCD.clrScr();
myGLCD.setFont(BigFont);
myGLCD.setColor(0, 0, 255);
myGLCD.print(" TEST ",CENTER, 1);
delay(1000);
myGLCD.clrScr();
}
void loop() {
ButtonState = digitalRead(buttonPin);
if(ButtonState && ButtonState != lastState) // button latch, no debounce needed.
{
if(buttonPushCounter < 2) // This will check to see if the count is within a range of 0 - 2, and anything over that, it will reset count back to 0. Of course, this will happen anyways because count is a BYTE, and not an int or any other type.
buttonPushCounter += 1; // same as count = count + 1;
else
buttonPushCounter = 0;
myGLCD.clrScr();
}
lastState = ButtonState;
switch (buttonPushCounter) {
case 0:
page1();
break;
case 1:
page2();
break;
case 2:
page3();
break;
}
}
You could put the reset functions inside the case statements before you load the pages. Or you can put them inside the pages themselves, whichever is easier for you.
i put them in the case statements for case 0 and 2 and now they re draw :D :D
i was having a play with this again and run in to a problem the gauges were taking a long time to draw a couple of seconds maybe and this was sometimes causing me to loose sync with the data form the ecu so i made a small edit to the library...
_Disp->setColor(WHITE);
_Disp->fillCircle(pos_x, pos_y, rad);
//drawArc(pos_x, pos_y, rad, rad, start, stop, WHITE);
//drawArc(pos_x, pos_y, rad, 0, start, stop, BLACK);
does not look quite as cool but draws and re-draws super quick and you can still set the sweep angle for the gauge, hope you don't mind.
If it helps you then that's fine. I will try to make it faster if I can.
gauge[_ID].x = pos_x + sin((value-90) * deg_to_rad) * (rad-2);
gauge[_ID].y = pos_y + cos((value-90) * deg_to_rad) * (rad-2);
you could remove the -90 from the formulas
sin(value -90) => -cos(value)
cos(value-90) => sin(value)
you might want to speed up the sin and cos like discussed here
- http://forum.arduino.cc/index.php?topic=69723.0 -
and
- http://forum.arduino.cc//index.php?topic=196625.msg1453433#msg1453433 -
make wrappers around a (PROGMEM) lookup table that works in degrees
the code would become faster but longer.
(there are 31 places in your lib where you use sin( x * degtorad) + 30 cos() == 60 places to speed up.
so the extra bytes might be worth the performance gain
If I have time, I will look into it, thanks robtillaart
I should have mentioned this earlier, if you look at the code for drawArc, you will see
for(float rotate = start; rotate <= stop; rotate+=0.5)
To draw an arc that spans 0 - 180 degrees, with a radius of 50 pixels and filled in, it takes 12.9 seconds. However if I make it increment by 1 instead of 0.5, then the time is cut in half, 6.5 seconds. There is a reason why it takes SO long to make the gauge, and that is because of the appearance. If I make it increment by 0.5, the gauge is filled and it looks good, no dead spots. However (you can try this if you want) if I make it increment by 1, then yes it will take half the time, but it won't look as nice.
Maybe I make it an option, Appearance vs Speed, and have it draw the gauges based on that setting.
There is always a method to the madness.
small test - // cos = sqrt(1-sin*sin); to calculate a faster cos()
"draw" your conclusions.
// Released to the public domain
uint32_t start;
uint32_t stop;
float deg_to_rad = 3.14159265/180;
int x;
int y;
void setup()
{
Serial.begin(115200);
Serial.println("Start ");
start = micros();
drawGauge(100, 10);
stop = micros();
Serial.println(stop - start);
start = micros();
drawGauge1(100, 10);
stop = micros();
Serial.println(stop - start);
Serial.println(x);
Serial.println(y);
}
void loop()
{
}
void drawGauge(int value, int rad)
{
x = sin((value-90) * deg_to_rad) * (rad-2);
y = cos((value-90) * deg_to_rad) * (rad-2);
}
void drawGauge1(int value, int rad)
{
x = sin((value-90) * deg_to_rad);
y = sqrt(1-x*x) * (rad-2); // cos = sqrt(1-sin*sin)
x = x * (rad-2);
}
iv got one more for you how could i get the HorBarGraph function to be at 0% on the left hand side and 100% on the right? as its going the opposite way atm?
do value = 100-value ?
I figured someone would want that so I modded the code to have it display both ways with a boolean variable.
Unfortunately, I am not home right now, so I can't post the library at the moment.
Update: look at SliderBar_Horizontal sketch.
Default is LTR.
Working on new Keyboard layout and adding sendable Smiley faces.
Ok got it great work. 8)
Minor Update: Added new functions for _Draw buttons.
User gromgsxr got me thinking, my buttons use locks to prevent them from constantly redrawing on screen, so, if you want to use them in a menu system, they wont redraw when you reenter the screen. It is the exact same issue gromgsxr was having with his gauges, once he left the screen and came back, they wouldn't redraw. Well these new functions will (as there names imply) fix that issue as either individually or all (of the same type) at once.
New Functions:
ResetTouchButton(byte ID);
ResetTouchCircle(byte ID);
ResetTouchTriangle(byte ID);
ResetLatchButton(byte ID);
ResetLatchCircle(byte ID);
ResetLatchTriangle(byte ID);
ResetAllTouchButton();
ResetAllTouchCircle();
ResetAllTouchTriangle();
ResetAllLatchButton();
ResetAllLatchCircle();
ResetAllLatchTriangle();
Added:
The rounded_Square function draws MUCH faster.
Notice:
I have a few new functions coming out soon. One is already done and its called TouchCircleByQuad
Basically it will return the quadrant of which you touched, (1,2,3 and 4) or you can specify a specific quadrant(s) and it will return true if it/they are touched.
The other two are Swipe and SwipeFromArea.
Swipe: Will return a value based on the direction you swiped on the screen from your initial touch(anywhere on screen). 1 = up, 2 = down, 3 = left and 4 = right. I am still fine tuning this function but it's not 100% yet.
SwipeFromArea: Needs an area to swipe from and a direction(x1, y1, x2, y2). This function will allow you to do things like, do something when only the bottom left side of the screen is swiped to the right or you can add multiple functions to do different things. Not 100% yet either.
I am also thinking of adding double tap buttons, but I don't know if they are really needed. But if someone wants them, I will add them.
UPDATE!
Library is below.
Slight update:
I fixed some things in the Smiley face function and got rid of the extra pixel at 0 deg.
And put the keyboard characters in the PROGMEM
good work!
small bug in the latest version in the CPP file on the top
#include "TFT_Extension_old.h"
Think it is time to include a version string in the library like
#define TFT_EXTENSION_VERSION "TFT EXT LIB V0.1.00"
Edit:
Sorry about that.
As for the version, there is most likely going to be one more coming out and that's the new keyboard layouts (iOS and Android style) and maybe a clock face, maybe.
Other than that, I think i'm finally done.
But I'll add the version in.
Below is just the .cpp file, you can replace the one you have with this one.
Ok, I think this is going to be the last update for this library, but I may tweak somethings here and there.
I started making this library, before it was ever a library, meaning at the time I was just adding functions to Karlsen's ITDB02 libraries, trying to make them better and more functional. Then before long I had written a LOT of new functions and decided to take what I made and make my own library that others can use. Its taken a collective 13 months, of both my ideas and help from other users (their names are in the .h file).
Thank you for finding this library helpful, and as always if there is something you want to add, by all means let me know. This is the last update from my ideas (because I'm all out), but if someone else has anything good that they want to add, I will add it.
Thank you again.
Edit: being that the iPhone and Android keyboards are very similar, I just made one new keyboard style, so now the library has Standard_Keyboard and Mobile_KeyBoard
Added: Updated library Discription
(OPTIONAL)
Its been a while since I did anything with my library, but I spent some time slimming it down a little (mostly the functions that dealt with color). I also added in a simple RGB to 565 color converter function. ConvertRGB(...)
As per the changes, I only modified a few of the example sketches that come with the library, such as Paint, Latching_Buttons, DrawBox, Arc, and Keyboard.
I am also trying to fix some of the visual functions like the sliders and bargraphs to look more pleasant to the eye.
Thanks a lot for your job!
Can you share this library on https://github.com (https://github.com), then I will add it to PlatformIO Library Register (http://platformio.ikravets.com/#!/lib).
I am in the process of setting up a Github account but I dont know how to use Github.
It's easy to use. Here is a few links:
- Google: github how to (https://www.google.com.ua/search?client=safari&rls=en&q=github+how+to&ie=UTF-8&oe=UTF-8&gfe_rd=cr&ei=ER80VLryHbGt8we5rYKQAg)
- GitHub Help (https://help.github.com)
I guess I did it.
https://github.com/AndrewMascolo/The-Libraries-I-use/
Looks great for beginning! But CVS (http://en.wikipedia.org/wiki/Concurrent_Versions_System)(like, SVN, GIT) was developed for keep track of all work and all changes in a set of files. This isn't good practice to keep in repository source that was packed in archive.
I recommend to create for each library separated repository with detailed information about it inside README.md file. See TOP examples by "arduino library (https://github.com/search?o=desc&q=arduino+library&s=stars&type=Repositories&utf8=?)" search query on GitHub:
- https://github.com/shirriff/Arduino-IRremote
- https://github.com/interactive-matter/aJson
and etc.
In your case the list of repositories:
- Arduino-OneWireKeypad
- Arduino-SeeedTouchScreen_V2
- Arduino-SerialServo
and etc..
P.S: Which OS type do you use?
This is the first time I have ever used Github and it is not straight forward or easy at all, so I'm surprised I was able to post anything.
recommend to create for each library separated repository with detailed information about it inside README.md file. See TOP examples by "arduino library" search query on GitHub:
I will look into that.
I am using Windows 8.1
Hi, nice library you've created, thanks for sharing. I'm interested in using the vertical slider but I'm using a 5" display and having troubles. When I load the example it shows 3 bars on the display with a box. The touch isn't working on the actual sliders, to move them I need to touch other areas of the screen and instead of sliding vertically I have to slide horizontally? The square box does show the color mix like it should.
I opened the .cpp file and saw the display resolution, I changed it to 800x480 but that doesn't seem to affect it any.
Do you have any idea?
Do you know if your touchscreen calibrated correctly? What screen orientation are you using and is it the same for the UTFT, UTouch and my library's setting?
Try this code and see if the values make sense. (Be sure to change the constructors)
#include <UTFT.h>
#include <UTouch.h>
// Declare which fonts we will be using
extern uint8_t SmallFont[];
//myGLCD(RS,WR,CS,RST,ALE,mode);
UTFT myGLCD(ITDB32S,A1,A2,A0,A3,A5);
//myTouch(TCLK,TCS,DIN,DOUT,IRQ);
UTouch myTouch(13,10,11,12,A4);
void setup()
{
myGLCD.InitLCD(LANDSCAPE);
myGLCD.clrScr();
myGLCD.setFont(SmallFont);
myTouch.InitTouch(LANDSCAPE);
myTouch.setPrecision(PREC_LOW);
myGLCD.fillScr(0,0,0);
}
void loop()
{
myTouch.read();
Debug(myTouch.getX(), myTouch.getY());
}
void Debug(int X, int Y)
{
myGLCD.setBackColor(0, 0, 0);//background of text is black
myGLCD.setColor(255,255,255); // test color is white
myGLCD.print("X: ", 0,0, 0);
if(X < 100){
myGLCD.print(" ", 29,0, 0);
myGLCD.printNumI(X, 24, 0);
}
else myGLCD.printNumI(X, 24, 0);
myGLCD.print("Y: ", 55,0,0);
if(Y < 100){
myGLCD.print(" ", 84,0, 0);
myGLCD.printNumI(Y, 79, 0);
}
else myGLCD.printNumI(Y, 79, 0);
}
UPDATE Version 1.3
Fixed keyboard color, added a few new functions for the Latch(Button/Circle/Triangle)_Draw functions. Now you can set/reset the state of the latch buttons to a specific state -> PRESSED or RELEASED. (Suggestion from No1Daemon)
ResetLatchButtonState
ResetAllLatchButtonState
ResetLatchCircleState
ResetAllLatchCircleState
ResetLatchTriangleState
ResetAllLatchTriangleState
See Latching Buttons example sketch.
Updated Constructor to just TFT_Extension myTFT(&myGLCD, &myTouch);, No need for landscape or portrait.
Added new Initializer function, myTFT.ExtSetup(); This will take care of the display size and orientation.
Fixed color pallet from RGB to 565 format.
As always, if you have an idea you want to add, let me know and I will be happy to add it. :)
Hello, I am building a home automation system with a 4,3" TFT LCD screen and i am having a wonderful time coding the visuals of the system with your library, but i have a few questions.
The main one is how i would go about making a custom shaped button, as for what i am designing i really need to figure out how to do this.
What i want to do is make a square button, accept the lower left hand corner of the button is cut off and there is a diagonal line instead. I really need the diagonal to start about 30 pixels back on both lines, then connect the two together.
The total button size is 145px long and 75px tall. Thanks, Isaac N.
You could just draw the shape and use TouchButton, not TouchButton_Draw.
TouchButton will work like TouchButton_Draw, but you wont see the button change colors when pressed.
The main issue that i am having is that i can not figure out how to draw the general shape, never the less make it into a button.
You would need to make your own functions to do custom shapes.
Something like this. (Untested)
void customShape(int x, int y, int w, int h, int Cx1, int Cy1, int Cx2, int Cy2, word Color)
{
float slope = (Cx2 - Cx1) / (Cy2 - Cy1);
for (int Dy = y; Dy < y + h; Dy++)
{
myGLCD.setColor(Color);
if (Dy < Cy1)
myGLCD.drawLine(x, Dy, x + w, Dy);
else
{
myGLCD.drawLine(x + slope * Dy, Dy, x + w, Dy);
}
}
}
Update to password sketch.
Password can be any length within the range of an unsigned long variable and pressing * or # will test the password as either PASS or FAIL.
#include <UTFT.h>
#include <UTouch.h>
#include <TFT_Extension.h>
// Declare which fonts we will be using
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
//myGLCD(RS,WR,CS,RST,ALE,mode);
UTFT myGLCD(ITDB32S, A1, A2, A0, A3, A5);
//myTouch(TCLK,TCS,DIN,DOUT,IRQ);
UTouch myTouch(13, 10, 11, 12, A4);
TFT_Extension myTFT(&myGLCD, &myTouch);
//For using the older ITDB02 libraries
//
//#include <ITDB02_Graph16.h>
//#include <ITDB02_Touch.h>
//#include <TFT_Extension_old.h>
//// Declare which fonts we will be using
//
//extern uint8_t SmallFont[];
//extern uint8_t BigFont[];
////myGLCD(RS,WR,CS,RST,ALE,mode);
//ITDB02 myGLCD(A1,A2,A0,A3,A5,ITDB32S);
////myTouch(TCLK,TCS,DIN,DOUT,IRQ);
//ITDB02_Touch myTouch(13,10,11,12,A4);
//TFT_Extension_old myTFT(&myGLCD, &myTouch);
char * PassText[4][3] = {
{"1", "2", "3"},
{"4", "5", "6"},
{"7", "8", "9"},
{"*", "0", "#"}
};
unsigned long MasterPassword = 2651; // can be any length within the range of an unsigned long variable
void setup()
{
myGLCD.InitLCD(LANDSCAPE);
myGLCD.setFont(SmallFont);
myTouch.InitTouch(LANDSCAPE);
myTouch.setPrecision(PREC_EXTREME);
myTFT.ExtSetup();
for (int line = 0; line <= 239; line++) // custom background color
{
myGLCD.setColor(0, 0, line);//text color White
myGLCD.drawLine(0, line, 319, line);
}
PassWord_makeButton();
PassWord_buttonText();
}
void loop()
{
GetPassword();
}
void PassWord_makeButton()
{
for (int y = 0; y < 300; y += 100)
{
for (int x = 0; x < 200; x += 50)
{
drawButton(20 + x, 90 + y, 50 + x, 30 + y); // this will draw the button on the screen by so many pixels
}
}
return;
}
void drawButton(int x1, int y1, int x2, int y2)
{
myGLCD.setColor(170, 170, 170); // grey
myGLCD.fillRoundRect(y1 - 3, x1 + 3, y2 - 3, x2 + 3); //Button Shading
myGLCD.setColor(255, 255, 255); // white
myGLCD.fillRoundRect(y1, x1, y2, x2);// outter button color
myGLCD.setColor(200, 0, 0); // red
myGLCD.fillRoundRect(y1 - 5, x1 + 5, y2 + 5, x2 - 5); //inner button color
return;
}
void PassWord_buttonText()
{
myGLCD.setFont(BigFont);
myGLCD.setBackColor(200, 0, 0);
myGLCD.setColor(255, 255, 255);
for (int tr = 0; tr < 300; tr += 100)
{
for (int tc = 0; tc < 200; tc += 50)
{
char *myText = PassText[tc / 50][tr / 100];
myGLCD.print(myText, 52 + tr, 27 + tc, 0); //this will print the number into the center of the buttons
}
}
}
void GetPassword()
{
bool PassFound = false, P_lock[12] = {false};
unsigned long password = 0;
byte i = 0;
while (PassFound == false)
{
for (int tr = 0; tr < 300; tr += 100)
{
for (int tc = 0; tc < 200; tc += 50)
{
if ( i < 12)
{
if (myTFT.TouchButton((90 + tr), (20 + tc), (30 + tr), (50 + tc)) && P_lock[i] == false) // this check to see if any of the buttons were pressed, then it sends the corresponding number to the "check" function
{
if (strcmp(PassText[tc / 50][tr / 100], "*") && strcmp(PassText[tc / 50][tr / 100], "#")) // pressing * or # will test the entered password
{
password = (password * 10) + ((PassText[tc / 50][tr / 100])[0]) - '0';
myGLCD.printNumI(password, CENTER, 1); // show the password as it is being entered
P_lock[i] = true;
}
else
{
PassFound = checkPassword(2651);
password = 0;
delay(1000);
myGLCD.print(" ", CENTER, 1);
}
}
else
P_lock[i] = false;
i++;
}
else
i = 0;
}
}
}
}
bool checkPassword(unsigned long P)
{
bool PF = false;
if (P == MasterPassword)
{
myGLCD.print("GOOD", CENTER, 1);
delay(1000);
myGLCD.print(" ", CENTER, 1);
PF = true;
}
else
{
myGLCD.print("FAIL", CENTER, 1);
delay(1000);
myGLCD.print(" ", CENTER, 1);
}
return PF;
}
BTW, I am still working on the new library, TFTExtensionV2.
Simple Calculator:
#include <UTFT.h>
#include <UTouch.h>
#include <TFT_Extension.h>
// Declare which fonts we will be using
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
//myGLCD(RS,WR,CS,RST,ALE,mode);
UTFT myGLCD(ITDB32S, A1, A2, A0, A3, A5);
//myTouch(TCLK,TCS,DIN,DOUT,IRQ);
UTouch myTouch(13, 10, 11, 12, A4);
TFT_Extension myTFT(&myGLCD, &myTouch);
//#include <ITDB02_Graph16.h>
//#include <ITDB02_Touch.h>
//#include <TFT_Extension_old.h>
//// Declare which fonts we will be using
//
//extern uint8_t SmallFont[];
//extern uint8_t BigFont[];
////myGLCD(RS,WR,CS,RST,ALE,mode);
//ITDB02 myGLCD(A1, A2, A0, A3, A5, ITDB32S);
////myTouch(TCLK,TCS,DIN,DOUT,IRQ);
//ITDB02_Touch myTouch(13, 10, 11, 12, A4);
//TFT_Extension_old myTFT(&myGLCD, &myTouch);
const byte ROWS = 4;
const byte COLS = 4;
char * keys[ROWS][COLS] = {
{"1", "2", "3", "+"},
{"4", "5", "6", "-"},
{"7", "8", "9", "x"},
{"C", "0", "=", "/"}
};
byte i = 0, N = 0;
char Type = 0;
bool lock = false, P = false;
long num[2] = {0};
float total = 0;
char Op = ' ';
char Values[20];
void setup()
{
myGLCD.InitLCD(LANDSCAPE);
myGLCD.setFont(SmallFont);
myTouch.InitTouch(LANDSCAPE);
myTouch.setPrecision(PREC_LOW);
myTFT.ExtSetup();
for (int line = 0; line <= 239; line++) // custom background color
{
myGLCD.setColor(0, 0, line);//text color White
myGLCD.drawLine(0, line, 319, line);
}
Calculator_makeButton();
Calculator_buttonText();
}
void loop()
{
Calculator();
}
void Calculator_makeButton()
{
for (int x = 0; x < 300; x += 75)
{
for (int y = 0; y < 200; y += 50)
{
drawButton(75 + x, 40 + y, 15 + x, 70 + y); // this will draw the button on the screen by so many pixels
}
}
return;
}
void drawButton(int x1, int y1, int x2, int y2)
{
myGLCD.setColor(170, 170, 170); // grey
myGLCD.fillRoundRect(x1 - 3, y1 + 3, x2 - 3, y2 + 3); //Button Shading
myGLCD.setColor(255, 255, 255); // white
myGLCD.fillRoundRect(x1, y1, x2, y2);// outter button color
myGLCD.setColor(200, 0, 0); // red
myGLCD.fillRoundRect(x1 - 5, y1 + 5, x2 + 5, y2 - 5); //inner button color
return;
}
void Calculator_buttonText()
{
myGLCD.setFont(BigFont);
myGLCD.setBackColor(200, 0, 0);
myGLCD.setColor(255, 255, 255);
for (int tr = 0; tr < 300; tr += 75)
{
for (int tc = 0; tc < 200; tc += 50)
{
char *myText = keys[tc / 50][tr / 75];
myGLCD.print(myText, 36 + tr, 47 + tc, 0); //this will print the number into the center of the buttons
}
}
}
void Calculator()
{
myGLCD.setBackColor(BLACK);
for (int tr = 0; tr < 300; tr += 75)
{
for (int tc = 0; tc < 200; tc += 50)
{
if (myTFT.TouchButton((75 + tr), (40 + tc), (15 + tr), (70 + tc)) && !strcmp((keys[tc / 50][tr / 75]), "=") ) // Check for equal sign is pressed
{
switch (Type)
{
case 0: total = num[0] + num[1]; break;
case 1: total = num[0] - num[1]; break;
case 2: total = num[0] * num[1]; break;
case 3: total = num[0] / num[1]; break;
}
Type = -1;
//Tft.fillRectangle(0, 30, 50, 20, BLACK);
myGLCD.setColor(WHITE);
myGLCD.printNumI(total, CENTER, 18);
delay(500);
num[0] = 0;
num[1] = 0;
total = 0;
N = 0;
Op = ' ';
}
if (myTFT.TouchButton((75 + tr), (40 + tc), (15 + tr), (70 + tc)) && !lock && ((tr / 75) != 3)) // make sure no operator is stored as a number
{
myGLCD.setColor(BLACK);
//myGLCD.fillRect(0, 0, 239, 20);
if (strcmp(keys[tc / 50][tr / 75], "C") && strcmp(keys[tc / 50][tr / 75], "=") ) // get numbers while they are not the equal sign
{
num[N] = (num[N] * 10) + ((keys[tc / 50][tr / 75])[0]) - '0';
myGLCD.setColor(WHITE);
//myGLCD.printNumI(num[N],0, 1);
lock = true;
}
}
if (myTFT.TouchButton((75 + tr), (40 + tc), (15 + tr), (70 + tc)) && ((tr / 75) == 3) )//check for an operator
{
Type = (tc / 50);
switch (Type)
{
case 0: Op = '+'; break;
case 1: Op = '-'; break;
case 2: Op = '*'; break;
case 3: Op = '/'; break;
}
//C_buttons[i].setForeColor(RED);
N = 1;
}
else
{
lock = false;
}
if (myTFT.TouchButton((75 + tr), (40 + tc), (15 + tr), (70 + tc)) && !strcmp(keys[tc / 50][tr / 75], "C"))//clear the screen
{
for (int line = 0; line <= 35; line++) // custom background color
{
myGLCD.setColor(0, 0, line);//text color White
myGLCD.drawLine(0, line, 319, line);
}
}
sprintf(Values, "%ld %c %ld", num[0], Op, num[1]);
myGLCD.setColor(WHITE);
myGLCD.print(Values, 0, 1);
}
}
}
Hi All,
I have a couple of questions regarding the code example edited by ghlawrence2000 on page #1 of this thread.
I've altered the code for my own use, for an 8 relay board 'on it's way from China'. "please ignore 'button' relay 9'', as it's only there for x/y co-ordinate reference.
Q1;
How can i change the colour 'color', of the buttons and the text with this sketch?
Q2;
How to o/p a on or of to the relay board. Would i be correct to add a statement to the end of each 'if' and 'else', IE;
while (true)
{
if (myTouch.dataAvailable())
{
pressed_button = myButtons.checkButtons();
if (pressed_button == but1)
if (Status1 == 0 ) {
myButtons.relabelButton(but1, "ON");
myButtons.drawButton(but1);
Status1 = 1;
digitlWrite(Relay_1, RELAY ON);
}
else
{
myButtons.relabelButton(but1, "OFF");
myButtons.drawButton(but1);
Status1 = 0;
digitalWrite(Relay_1, RELAY OFF);
}
This would be in 'void loop', after declaring;
#define RELAY_ON 0;
#define RELAY_OFF 1;
#define RELAY_1 2 // relay 1 o/p pin 2
Then in 'void setup';
digitalWrite(Relay_1, RELAY_OFF); // working with an active 'low' relay board.
pinMode(Relay_1, OUTPUT);
Sorry if this is confusing. Any advice would be appreciated.
#include <UTFT.h>
#include <UTouch.h>
#include <UTFT_Buttons.h>
//#include <UTFT_tinyFAT.h>
//#include <tinyFAT.h>
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
// Remember to change the model parameter to suit your display module!
UTFT myGLCD(ILI9327, 38, 39, 40, 41);
UTouch myTouch( 6, 5, 4, 3, 2);
// Finally we set up UTFT_Buttons :)
UTFT_Buttons myButtons(&myGLCD, &myTouch);
// Finally we set up UTFT_tinyFAT :)
//UTFT_tinyFAT myFiles(&myGLCD);
void setup()
{
//file.initFAT();
myGLCD.InitLCD();
myGLCD.clrScr();
myGLCD.setFont(SmallFont);
myTouch.InitTouch();
myTouch.setPrecision(PREC_HI);
//myFiles.loadBitmap(30, 100, 300, 300, "power.raw");
//myFiles.loadBitmap(100, 400, 700, 50,"shutdown.bmp"); // <=== Good luck with that! ;)
}
void loop()
{
int but1, but2, but3, but4, but5, but6, but7, but8, but9, but10, but11, but12, butX, butY, pressed_button, x, y;
int Status1 = 0, Status2 = 0, Status3 = 0, Status4 = 0, Status5 = 0, Status6 = 0, Status7 = 0, Status8 = 0, Status9 = 0, Status10 = 0; // <== ! You had not initialised these
// Menu
myButtons.setTextFont(SmallFont);
myButtons.setButtonColors(VGA_BLACK, VGA_GRAY, VGA_WHITE, VGA_RED, VGA_WHITE);
but1 = myButtons.addButton(10, 10, 80, 70, "Relay 1");
but2 = myButtons.addButton(110, 10, 80, 70, "Relay 2");
but3 = myButtons.addButton(210, 10, 80, 70, "Relay 3");
but4 = myButtons.addButton(310, 10, 80, 70, "Relay 4");
but5 = myButtons.addButton(10, 100, 80, 70, "Relay 5");
but6 = myButtons.addButton(110, 100, 80, 70, "Relay 6");
but7 = myButtons.addButton(210, 100, 80, 70, "Relay 7");
but8 = myButtons.addButton(310, 100, 80, 70, "Relay 8");
but9 = myButtons.addButton(220, 180, 180, 70, "Relay 9");
//but5 = myButtons.addButton(409, 100, 379, 70, "LED slang");
myButtons.drawButtons();
while (true)
{
if (myTouch.dataAvailable())
{
pressed_button = myButtons.checkButtons();
if (pressed_button == but1)
if (Status1 == 0 ) {
myButtons.relabelButton(but1, "ON");
myButtons.drawButton(but1);
Status1 = 1;
}
else
{
myButtons.relabelButton(but1, "OFF");
myButtons.drawButton(but1);
Status1 = 0;
}
if (pressed_button == but2)
if (Status2 == 0 ) {
myButtons.relabelButton(but2, "ON");
myButtons.drawButton(but2);
Status2 = 1;
}
else {
myButtons.relabelButton(but2, "OFF");
myButtons.drawButton(but2);
Status2 = 0;
}
if (pressed_button == but3)
if (Status3 == 0 ) {
myButtons.relabelButton(but3, "ON");
myButtons.drawButton(but3);
Status3 = 1;
}
else {
myButtons.relabelButton(but3, "OFF");
myButtons.drawButton(but3);
Status3 = 0;
}
if (pressed_button == but4)
if (Status4 == 0 ) {
myButtons.relabelButton(but4, "ON");
myButtons.drawButton(but4);
Status4 = 1;
}
else {
myButtons.relabelButton(but4, "OFF");
myButtons.drawButton(but4);
Status4 = 0;
}
if (pressed_button == but5)
if (Status5 == 0 ) {
myButtons.relabelButton(but5, "ON");
myButtons.drawButton(but5);
Status5 = 1;
}
else {
myButtons.relabelButton(but5, "OFF");
myButtons.drawButton(but5);
Status5 = 0;
}
if (pressed_button == but6)
if (Status6 == 0 ) {
myButtons.relabelButton(but6, "ON");
myButtons.drawButton(but6);
Status6 = 1;
}
else {
myButtons.relabelButton(but6, "OFF");
myButtons.drawButton(but6);
Status6 = 0;
}
if (pressed_button == but7)
if (Status7 == 0 ) {
myButtons.relabelButton(but7, "ON");
myButtons.drawButton(but7);
Status7 = 1;
}
else {
myButtons.relabelButton(but7, "OFF");
myButtons.drawButton(but7);
Status7 = 0;
}
if (pressed_button == but8)
if (Status8 == 0 ) {
myButtons.relabelButton(but8, "ON");
myButtons.drawButton(but8);
Status8 = 1;
}
else {
myButtons.relabelButton(but8, "OFF");
myButtons.drawButton(but8);
Status8 = 0;
}
if (pressed_button == but9)
if (Status9 == 0 ) {
myButtons.relabelButton(but9, "ON");
myButtons.drawButton(but9);
Status9 = 1;
}
else {
myButtons.relabelButton(but9, "OFF");
myButtons.drawButton(but9);
Status9 = 0;
}
if (pressed_button == but10)
if (Status10 == 0 ) {
myButtons.relabelButton(but10, "ON");
myButtons.drawButton(but10);
Status10 = 1;
}
else {
myButtons.relabelButton(but10, "OFF");
myButtons.drawButton(but10);
Status10 = 0;
}
}
}
}/code]
I have a couple of questions regarding the code example edited by ghlawrence2000 on page #1 of this thread.
? I think you have the wrong thread, but to answer your questions anyway.
Q1;
How can i change the colour 'color', of the buttons and the text with this sketch?
myButtons.setButtonColors(VGA_BLACK, VGA_GRAY, VGA_WHITE, VGA_RED, VGA_WHITE);
Q2;
How to o/p a on or of to the relay board. Would i be correct to add a statement to the end of each 'if' and 'else', IE;
o/p ?
If the button can be
renamed ON or OFF, then you can also make the relay for that button be ON or OFF too, with digitalWrite( "relay number", HIGH); or digitalWrite( "relay number", LOW);
Hi All,
HazardsMind, Thank you for your reply and input. Very grateful. You are correct, sorry posted in the wrong thread. I lost my way, being that the correct thread has a lot of input and advise from yourself.
The correct thread would have been;
http://forum.arduino.cc/index.php?topic=287212.msg2014284#msg2014284
Sorry for that, and the unexpected hack of your Library thread.
I do have some more questions, regarding my post and your reply, that i'll post in the above 'correct', thread.
Dizzwold.
For those having issues with my Connect Four game using Bluetooth, there was a small thing I left out. Please see the revised function and my apologizes for the inconvenience.
void Bluetooth_Play()
{
boolean PLAY = false;
int col;
if (Player == Host) // guest
{
if (Serial1.available() > 0)
{
col = Serial1.read() - '0';
newRow = CheckMap(col);
PLAY = true;
}
else
{
myGLCD.setFont(SmallFont);
myGLCD.print("Waiting", CENTER, 37);
myGLCD.setFont(BigFont);
}
}
else
{
myGLCD.setFont(SmallFont);
myGLCD.print(" ", CENTER, 37);
myGLCD.setFont(BigFont);
for (col = 0; col < 9; col++)
{
if (myTFT.TouchButton(45 + col * 25, 50, 72 + col * 25, 195))
{
newRow = CheckMap(col);
Serial1.print(col + '0');
PLAY = true;
break;
}
}
}
if (PLAY)
{
if (!MapFull[col])
{
Remaining--;
addToMap(col, (newRow), Player);
dropChipAnimation(col, newRow);
if (newRow == 0) MapFull[col] = true;
if (!ScanHorizontal() && !ScanVertical() && !ScanDiag())
Player = !Player;
else
WINNER = Player + 1;
}
else
{
myGLCD.setFont(SmallFont);
myGLCD.setColor(RED);
myGLCD.print("Pick another column", CENTER, 37);
delay(500);
myGLCD.print(" ", CENTER, 37);
}
PLAY = false;
}
}
Serial1.print(col + '0'); sends the other arduino the location to put the chip that the other user placed. Above I am subtracting the ascii character zero from the serial read, but I forgot to add it to the col variable when I send it out. The reason I did it this way, was to make it easy for me to debug the game while using my laptop in-place of another arduino.
Hi,
Will this work with any LCD using a Henning UTFT Lib? Currently using a HX8357B LCD + Henning UTFT. Tried some minor editing (like removing utouch). But kept getting compilation errors (mostly "not defined")
Interested mainly with the Arc and Gauge.
Thanks
Unfortunately you will need to include the Utouch library, yes.
I haven't figured out how to keep the compiler happy without it ( atleast not without using a template)
Even with Utouch it still won't compile.. :(
Anyways I was trying out some code you posted TFT analog gauge (http://forum.arduino.cc/index.php?topic=216078.0). Just need to figure out how to make it sweep from left to right and maybe use the fillrect.
Edit: I forgot to add something to the last upload. Problem was fixed.
UPDATE: Version 1.4.
I did this with my newer version that I am still developing (sorry it is taking so long), But I made it so when you press a _Draw button, the text will change depending on the state of the button. So now you can have ON when pressed and OFF when not pressed. Same goes for the latching buttons. Also the text color will invert its set color if the button background is the same as the text color.
**If the button is black and the text color is also black, the text will change to white.**
See Latching Button example.
Link to Library:
https://github.com/AndrewMascolo/TFT_Extension
Halo frnz..help me to use TFT_extention library.while using that,i got an error mez like "no such file or directory"
Where did you put the library?
Hi HazardsMind,
Heres my problem. Ignore the blob in button 1 area, it's the protective film thats blistered.
Photo 1 is start / reset.
Photo 2 is menu button pressed, to get menu 2.
Photo 3 is menu button pressed, to go back to menu 1.
Photo 4 is menu button pressed, to goto menu 2 again.
From then on, every time the menu button is pressed, all i get is photo 3 or 4?
Dizzwold.
I know you don't want to copy my code directly, so show me what your code looks like.
Whenever I give you a code I test it fully to make sure it looks and works correctly.
Hi HazardsMind,
Heres the code. The only things that i should have changed is for my controller and touch, button sizes and the on screen data.
Dizzwold.
#include <UTFT.h>
#include <UTouch.h>
#include <TFT_Extension.h>
UTFT myGLCD(ILI9327, 38, 39, 40, 41);
UTouch myTouch( 6, 5, 4, 3, 2);
TFT_Extension myTFT(&myGLCD, &myTouch);
#include <VirtualWire.h>
char remote[4] = {'X', 'Y', 'Z', '\0'};
byte Data = 0;
extern uint8_t SmallFont[];
void setup()
{
//Serial.begin(57600);
// Initialise the IO and ISR
vw_setup(2000); // Bits per sec, must match receiver.
vw_set_tx_pin(51); // Data Pin, change for your needs
myGLCD.InitLCD(LANDSCAPE);
myGLCD.clrScr();
myGLCD.setFont(SmallFont);
myTouch.InitTouch(LANDSCAPE);
myTouch.setPrecision(PREC_MEDIUM);
//pinMode(53, OUTPUT); // for my purposes
//digitalWrite(53, HIGH); // for my purposes
myTFT.ExtSetup();
myTFT.SetLatchButtonColors(0, GREEN, BLUE, FILL, ROUNDED);
myTFT.SetLatchButtonText(0, "Menu 2", "Menu 1", Small, WHITE);
myGLCD.fillScr(BLACK);
}
void loop()
{
static byte last = 255, lastMenu = 255;
byte MenuButton = myTFT.LatchButton_Draw(110, 190, 290, 220, 0);
if (MenuButton != lastMenu) // set button colors
{
lastMenu = MenuButton;
if (MenuButton == 0)
Menu_1();
else
Menu_2();
myTFT.ResetAllLatchButton();
}
bitWrite(Data, 0, myTFT.LatchButton_Draw(10, 10, 90, 80, 1 + (MenuButton ? 8 : 0)));
bitWrite(Data, 1, myTFT.LatchButton_Draw(110, 10, 190, 80, 2 + (MenuButton ? 8 : 0)));
bitWrite(Data, 2, myTFT.LatchButton_Draw(210, 10, 290, 80, 3 + (MenuButton ? 8 : 0)));
bitWrite(Data, 3, myTFT.LatchButton_Draw(310, 10, 390, 80, 4 + (MenuButton ? 8 : 0)));
bitWrite(Data, 4, myTFT.LatchButton_Draw(10, 100, 90, 170, 5 + (MenuButton ? 8 : 0)));
bitWrite(Data, 5, myTFT.LatchButton_Draw(110, 100, 190, 170, 6 + (MenuButton ? 8 : 0)));
bitWrite(Data, 6, myTFT.LatchButton_Draw(210, 100, 290, 170, 7 + (MenuButton ? 8 : 0)));
bitWrite(Data, 7, myTFT.LatchButton_Draw(310, 100, 390, 170, 8 + (MenuButton ? 8 : 0)));
if (MenuButton == 0)
remote[1] = Data;
else
remote[2] = Data;
if (Data != last) // Debug and see what the value is
/*{
myGLCD.setColor(BLACK);
myGLCD.print(" ", 0, 220);
myGLCD.printNumI(int(Data), 0, 220);
last = Data;
}*/
if (Data == 0)
{
remote[0] = 'X';
remote[1] = 0xFF;
remote[2] = 0xFF;
}
else
remote[0] = 'A';
//myGLCD.printChar(remote[0], 0, 200);
vw_send((uint8_t *)remote, strlen(remote));
}
void Menu_1()
{
myGLCD.clrScr();
myTFT.SetLatchButtonColors(1, PURPLE, BLUE, FILL, ROUNDED);
myTFT.SetLatchButtonText(1, "ON", "OFF", Small, WHITE);
myTFT.SetLatchButtonColors(2, PURPLE, BLUE, FILL, ROUNDED);
myTFT.SetLatchButtonText(2, "ON", "OFF", Small, WHITE);
myTFT.SetLatchButtonColors(3, PURPLE, BLUE, FILL, ROUNDED);
myTFT.SetLatchButtonText(3, "ON", "OFF", Small, WHITE);
myTFT.SetLatchButtonColors(4, PURPLE, BLUE, FILL, ROUNDED);
myTFT.SetLatchButtonText(4, "ON", "OFF", Small, WHITE);
myTFT.SetLatchButtonColors(5, PURPLE, BLUE, FILL, ROUNDED);
myTFT.SetLatchButtonText(5, "ON", "OFF", Small, WHITE);
myTFT.SetLatchButtonColors(6, PURPLE, BLUE, FILL, ROUNDED);
myTFT.SetLatchButtonText(6, "ON", "OFF", Small, WHITE);
myTFT.SetLatchButtonColors(7, PURPLE, BLUE, FILL, ROUNDED);
myTFT.SetLatchButtonText(7, "ON", "OFF", Small, WHITE);
myTFT.SetLatchButtonColors(8, PURPLE, BLUE, FILL, ROUNDED);
myTFT.SetLatchButtonText(8, "ON", "OFF", Small, WHITE);
//myTFT.SetLatchButtonColors(0, GREEN, BLUE, FILL, ROUNDED);
//myTFT.SetLatchButtonText(0, "Menu 2", "Menu 1", Small, WHITE);
}
void Menu_2()
{
// myGLCD.clrScr();
myTFT.SetLatchButtonColors(1 + 8, PURPLE, GREEN, FILL, ROUNDED);
myTFT.SetLatchButtonText(1 + 8, "ON", "OFF", Small, WHITE);
myTFT.SetLatchButtonColors(2 + 8, PURPLE, GREEN, FILL, ROUNDED);
myTFT.SetLatchButtonText(2 + 8, "ON", "OFF", Small, WHITE);
myTFT.SetLatchButtonColors(3 + 8, PURPLE, GREEN, FILL, ROUNDED);
myTFT.SetLatchButtonText(3 + 8, "ON", "OFF", Small, WHITE);
myTFT.SetLatchButtonColors(4 + 8, PURPLE, GREEN, FILL, ROUNDED);
myTFT.SetLatchButtonText(4 + 8, "ON", "OFF", Small, WHITE);
myTFT.SetLatchButtonColors(5 + 8, PURPLE, GREEN, FILL, ROUNDED);
myTFT.SetLatchButtonText(5 + 8, "ON", "OFF", Small, WHITE);
myTFT.SetLatchButtonColors(6 + 8, PURPLE, GREEN, FILL, ROUNDED);
myTFT.SetLatchButtonText(6 + 8, "ON", "OFF", Small, WHITE);
myTFT.SetLatchButtonColors(7 + 8, PURPLE, GREEN, FILL, ROUNDED);
myTFT.SetLatchButtonText(7 + 8, "ON", "OFF", Small, WHITE);
myTFT.SetLatchButtonColors(8 + 8, PURPLE, GREEN, FILL, ROUNDED);
myTFT.SetLatchButtonText(8 + 8, "ON", "OFF", Small, WHITE);
//myTFT.SetLatchButtonColors(0, GREEN, BLUE, FILL, ROUNDED);
//myTFT.SetLatchButtonText(0, "Menu 2", "Menu 1", Small, WHITE);
}/code]
You should have done this a long way back, but since we are using more buttons, you need to update
NumOfButtons in the TFT_Extension.h file. Make it 20 and save, that should clear up the weird Big font issue you are having with your buttons.
Also the clrScr should be commented out from here. This is what is causing your menu button to not work correctly.
void Menu_1()
{
myGLCD.clrScr();
Hi HazardsMind,
How stupid do i feel. Stupid stupid school-boy-error.
Dizzwold.
I've been reading into saving the button states for power saving with a physical on off switch.
I was looking at first, to use the EEPROM, but from reading, most advise is to avoid using the EEPROM, but to us SPRAM instead.
The EEPROM can be used apparently 100,000 times.
Any thoughts on this.
Dizzwold.
Sorry, just read SPRAM = Volatile.
I guess it would have to be EEPROM.
Dizzwold.
Does your display have an SD card slot?
Yeah. But from reading others with a similar TFT, it's not that reliable?
Dizzwold
How so? Have you tried it with your display? All you need to be able to do is be able to write and read two bytes.
To be honest, i've never given it a thought.
Dizzwold.
Give it a try.
To begin with, I wouldn't know where to start, i've never looked at using an SD card. Mostly because of the bed reports i've read and the lack of information.
Since my last post i've been trying to find a pin-out for my TFT.
I've found a board, not quite identical to the 1 in the following Arduino Russia site, post 320.
I have the 3.6" mcufriend unit. The touch controller IC in the upper right, is on my board in the upper left between the double header and the touch pins, but looking a broken TFT i have the pins-outs are the same.
Actually if you goto posts 327 & 328, this is my exact unit.
Also on the previous page, #6, post 274, there are some comments about having to add extra 10k resistors in addition to the resistor packs.
Regarding the extra 10k resistors, this is possibly why i've read bad reports about using the SD card.
Now i've found this wealth of info on my units, i know there are many others on this 'the english forum', that have had the same problems, not knowing pin-out, touch controller and screen controller. This on it's own deserves it's own thread.
Dizzwold.
Hi HazardsMind,
Forgot my manners earlier with my shame.
Thank you for proof read my error. LOL.
Thank you for your assistance.
Dizzwold.
I was playing around with the transmitter sketch and my new library, TFT_ExtensionV2. And although the sketch size in bytes wasn't that different from the one you have now, the global variable usage was incredibly less!
You might not know what this means, but it is VERY good for the SRAM usage (something very precious and limited).
Using my new library, the global variable usage was around 312 bytes, but the one you have now uses 2000+ bytes. Yikes.
Big difference and yet the code looks nicer, performs faster and even the visuals look better. The buttons have padding now, so you get a white rim around the buttons (color can be changed).
The only problem with my new library is, its quite a steep learning curve. Each button is its own class and only uses the memory it needs to work instead of wasting memory on things that are not needed or are never used. I put in all the same features like regular touch and release, latching and even delay touch.
Same 3 types too, Box, Circle and Triangle, but I am also working on allowing the user to design their own custom button. So if you want a button that's a star or a trapezoid, you can now have it. You can also make crazy shapes and it will still function as a button.
I am still deciding whether or not to give you the library, only because it will be an enormous learning curve for you and also because I can see you are still struggling with my current library.
I'll get back to you on that decision.
Hi HazardsMind,
Photos as promised. Sorry for the blurring, but you get the idea.
Dizzwold.
@Dizzworld: i did the same thing for my 5' screen :-)
There i just one difference: Is splitted the pins for 3.3v and 5V by using an SPI (2x3) connector and soldered some pins together. Now i have 1x6 or 2 inputs for 3.3V, 2 for 5v and 2 for Ground. 3 pins are in use for my screen, 3 are left to do other stuff.
I have an etherDue with Power over ethernet, the reset button is located in the middle of the board instead of the edge of the board. (like most arduino's) :-(
So i added the blue cable as reset line. I just touch the other end of the cable against the ethernetjack to reset my board. :-)
Now i'm looking for a descent GUI library to use. But it seems hard to find these libs...
Hi VinzzB,
Firstly, i'm no master or guru on this subject. The main issue is what is the display driver / controller, but you won't find this from looking. You would basically have to take the TFT apart 'destroy it' ,to find out.
Do you have any other information on the TFT?
Can you contact the vendor / seller for more info?
That's the best start i can advise, with-out more info.
I use Henning Karlsen's UTFT & UTouch libraries. Please donate to Henning, as he has put a lot of time into his libraries.
The reason i've documented some stuff on the TFT 'that i have', is because, so little is known about it. A very poorly documented unit. The most of the information i have found, have been on Russian sites.
If you can give more info on your TFT, i'm more than willing to help if i can.
Dizzwold.
Hi HazardMind I have a few problems with your last Password Sketch from here
http://forum.arduino.cc/index.php?topic=217873.75#bot
first BUG
if I just press the * button and nothing else the display prints GOOD
the same
if I just press the # button and nothing else the display prints GOOD
second BUG
if I just press 3 and then * button the display prints GOOD
the same
if I just press 3 and then # button the display prints GOOD
The password is not checked , it´s always good
I use
IDE 1.6.5
UTFT last
UTouch last
TFT_Extension from your Github
easyplayer
Thats because of this here.
else
{
PassFound = checkPassword(2651);
password = 0;
delay(1000);
myGLCD.print(" ", CENTER, 1);
}
I don't remember if I did this just as a test, but 2651 should be replaced with
password
Hi, thanks for your help .
I am a beginner and do that only as a hobby.
thank you for sharing i give your some `karma`
easyplayer