TFT Game by Areeb

if you are fond of doing paint and want to make something related to that. So Here is the project for you.

This Project is a Painting Software Based on TFT touchscreen
This project have Many Feature like:-
  1. Various Color Choices 
  2. Can Change pensize
  3. Different games layout like | i}tic-tac-toe | ii}Word Game | ii}Complete LOGO 
  4. Different Pen Shape like |i}line | ii}Circle | ii}Square
  5. Help Button For New User 


  Material needed:-
  • Arduino UNO(can use mega also)
  • Arduino TFT touchScreen Sheild (buy it here)

How To Make :-

This Project is Very Easy to make Just You Have To Fit the TFT shield on the Arduino
And Then Just upload the code 
/*
 * Arduino TFT Paint
 * by Areeb-ur-Rub
 * FaceBook Page:-http://fb.me/diyareeb
 */

 // Don't Change These information 
#include <Adafruit_GFX.h>    
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;       
#include <TouchScreen.h>

#if defined(__SAM3X8E__)
#undef __FlashStringHelper::F(string_literal)
#define F(string_literal) string_literal
#endif



// These are the pins for some typical shields!
// S6D0154: YP=A1, XM=A2, YM=7, XP=6
// ST7783 : YP=A2, XM=A1, YM=6, XP=7
// ILI9320: YP=A2, XM=A3, YM=8, XP=9
// ILI9325: YP=A1, XM=A2, YM=7, XP=6
// ILI9325BG: YP=A2, XM=A1, YM=6, XP=7
// ILI9341: YP=A2, XM=A1, YM=7, XP=6
// ILI9488: YP=A1, XM=A2, YM=7, XP=6
// R65109V: YP=A2, XM=A1, YM=6, XP=7

// Change the Below data using above information
uint8_t YP = A1;  
uint8_t XM = A2;  
uint8_t YM = 7;   
uint8_t XP = 6;   

 //Don't Change the Swap Value 
//It is For Screen Adaptment
uint8_t SwapXY = 0;

char  M,LOGO;
long Rand;
#define RGB(r, g, b) (((r&0xF8)<<8)|((g&0xFC)<<3)|(b>>3))

//Can Change The RGB value of The Color
//According to Use
#define  RED2                RGB(255, 33, 33)
#define  RED3                RGB(255, 92, 33) 
#define  ORANGE              RGB(255, 133, 33) 
#define  BROWN               RGB(255, 177, 33) 
#define  GOLD                RGB(255, 199, 33) 
#define  LIME                RGB(255, 225, 33) 
#define  LIME2               RGB(236, 255, 33) 
#define  GREEN1              RGB(192, 255, 33) 
#define  GREEN2              RGB(137, 255, 33) 
#define  GREEN3              RGB(78, 255, 33) 
#define  GREEN4              RGB(33, 255, 41) 
#define  BLUE1               RGB(33, 255, 177) 
#define  BLUE2               RGB(33, 255, 225) 
#define  BLUE3               RGB(33, 199, 255) 
#define  BLUE4               RGB(33, 144, 255) 
#define  BLUE5               RGB(33, 74, 255) 
#define  BLUE6               RGB(81, 33, 255) 
#define  PURPUL1             RGB(140, 33, 255) 
#define  PURPUL2             RGB(188, 33, 255) 
#define  PURPUL3             RGB(232, 33, 255) 
#define  PINK1               RGB(255, 33, 243) 
#define  PINK2               RGB(255,33,188) 

//Don't Change These By Default Values
uint16_t TS_LEFT = 920;
uint16_t TS_RT  = 150;
uint16_t TS_TOP = 940;
uint16_t TS_BOT = 120;
char *name = "Unknown controller";


// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
TSPoint tp;

#define MINPRESSURE 20
#define MAXPRESSURE 1000

#define SWAP(a, b) {uint16_t tmp = a; a = b; b = tmp;}

int16_t BOXSIZE;
int PENRADIUS = 0;
uint16_t identifier, oldcolor, currentcolor;
uint8_t Orientation = 0;    //PORTRAIT

// Assign human-readable names to some common 16-bit color values:
#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF


void setup(void)
{
    //int Data
    uint16_t tmp;
    
    tft.reset();
    identifier = tft.readID();

    
    //    if (identifier == 0) identifier = 0x9341;
    if (0) {
    } else if (identifier == 0x0154) {
        name = "S6D0154";
        TS_LEFT = 914; TS_RT = 181; TS_TOP = 957; TS_BOT = 208;
    } else if (identifier == 0x7783) {
        name = "ST7781";
        TS_LEFT = 865; TS_RT = 155; TS_TOP = 150; TS_BOT = 942;
        SwapXY = 1;
    } else if (identifier == 0x7789) {
        name = "ST7789V";
        YP = A2; XM = A1; YM = 7; XP = 6;
        TS_LEFT = 906; TS_RT = 169; TS_TOP = 161; TS_BOT = 919;
    } else if (identifier == 0x9320) {
        name = "ILI9320";
        YP = A3; XM = A2; YM = 9; XP = 8;
        TS_LEFT = 902; TS_RT = 137; TS_TOP = 941; TS_BOT = 134;
    } else if (identifier == 0x9325) {
        name = "ILI9325";
        TS_LEFT = 900; TS_RT = 103; TS_TOP = 96; TS_BOT = 904;
    } else if (identifier == 0x9325) {
        name = "ILI9325 Green Dog";
        TS_LEFT = 900; TS_RT = 130; TS_TOP = 940; TS_BOT = 130;
    } else if (identifier == 0x9327) {
        name = "ILI9327";
        TS_LEFT = 899; TS_RT = 135; TS_TOP = 935; TS_BOT = 79;
        SwapXY = 1;
    } else if (identifier == 0x9329) {
        name = "ILI9329";
        TS_LEFT = 143; TS_RT = 885; TS_TOP = 941; TS_BOT = 131;
        SwapXY = 1;
    } else if (identifier == 0x9341) {
        name = "ILI9341 BLUE";
        TS_LEFT = 920; TS_RT = 139; TS_TOP = 944; TS_BOT = 150;
        SwapXY = 0;
    } else if (identifier == 0) {
        name = "ILI9341 DealExtreme";
        TS_LEFT = 893; TS_RT = 145; TS_TOP = 930; TS_BOT = 135;
        SwapXY = 1;
    } else if (identifier == 0 || identifier == 0x9341) {
        name = "ILI9341";
        TS_LEFT = 128; TS_RT = 911; TS_TOP = 105; TS_BOT = 908;
        SwapXY = 1;
    } else if (identifier == 0x9486) {
        name = "ILI9486";
        TS_LEFT = 904; TS_RT = 170; TS_TOP = 950; TS_BOT = 158;
    } else if (identifier == 0x9488) {
        name = "ILI9488";
        TS_LEFT = 904; TS_RT = 170; TS_TOP = 950; TS_BOT = 158;
    } else if (identifier == 0xB509) {
        name = "R61509V";
        TS_LEFT = 889; TS_RT = 149; TS_TOP = 106; TS_BOT = 975;
        SwapXY = 1;
    } else {
        name = "unknown";
    }
    switch (Orientation) {      // adjust for different aspects
        case 0:   break;        //no change,  calibrated for PORTRAIT
        case 1:   tmp = TS_LEFT, TS_LEFT = TS_BOT, TS_BOT = TS_RT, TS_RT = TS_TOP, TS_TOP = tmp;  break;
        case 2:   SWAP(TS_LEFT, TS_RT);  SWAP(TS_TOP, TS_BOT); break;
        case 3:   tmp = TS_LEFT, TS_LEFT = TS_TOP, TS_TOP = TS_RT, TS_RT = TS_BOT, TS_BOT = tmp;  break;
    }

    Serial.begin(9600);
    ts = TouchScreen(XP, YP, XM, YM, 300);     //call the constructor AGAIN with new values.
    
    tft.begin(identifier);//Can Change the word Indentifier 
                         //by the model number of tft 
                        //Can check it on http://goo.gl/search/
                        
    tft.setRotation(Orientation);//dont change it
    tft.fillScreen(BLACK);
    BOXSIZE = tft.width() / 23;//partition for the color picker
    
    tft.fillScreen(BLACK);
    tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED2);
    tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, RED3);
    tft.fillRect(BOXSIZE * 2, 0, BOXSIZE, BOXSIZE, ORANGE);
    tft.fillRect(BOXSIZE * 3, 0, BOXSIZE, BOXSIZE, BROWN);
    tft.fillRect(BOXSIZE * 4, 0, BOXSIZE, BOXSIZE, GOLD);
    tft.fillRect(BOXSIZE * 5, 0, BOXSIZE, BOXSIZE, LIME);
    tft.fillRect(BOXSIZE * 6, 0, BOXSIZE, BOXSIZE, LIME2);
    tft.fillRect(BOXSIZE * 7, 0, BOXSIZE, BOXSIZE, GREEN1);
    tft.fillRect(BOXSIZE * 8, 0, BOXSIZE, BOXSIZE, GREEN2);
    tft.fillRect(BOXSIZE * 9, 0, BOXSIZE, BOXSIZE, GREEN3);
    tft.fillRect(BOXSIZE * 10, 0, BOXSIZE, BOXSIZE, GREEN4);
    tft.fillRect(BOXSIZE * 11, 0, BOXSIZE, BOXSIZE, BLUE1);
    tft.fillRect(BOXSIZE * 12, 0, BOXSIZE, BOXSIZE, BLUE2);
    tft.fillRect(BOXSIZE * 13, 0, BOXSIZE, BOXSIZE, BLUE3);
    tft.fillRect(BOXSIZE * 14, 0, BOXSIZE, BOXSIZE, BLUE4);
    tft.fillRect(BOXSIZE * 15, 0, BOXSIZE, BOXSIZE, BLUE5);
    tft.fillRect(BOXSIZE * 16, 0, BOXSIZE, BOXSIZE, BLUE6);
    tft.fillRect(BOXSIZE * 17, 0, BOXSIZE, BOXSIZE, PURPUL1);
    tft.fillRect(BOXSIZE * 18, 0, BOXSIZE, BOXSIZE, PURPUL2);
    tft.fillRect(BOXSIZE * 19, 0, BOXSIZE, BOXSIZE, PURPUL3);
    tft.fillRect(BOXSIZE * 20, 0, BOXSIZE, BOXSIZE, PINK1);
    tft.fillRect(BOXSIZE * 21, 0, BOXSIZE, BOXSIZE, PINK2);
    tft.fillRect(BOXSIZE * 22, 0, BOXSIZE, BOXSIZE, BLACK);
    tft.fillRect(BOXSIZE * 23, 0, BOXSIZE, BOXSIZE, WHITE);
    
    // Status bar Design
     tft.fillRect(0, BOXSIZE, BOXSIZE,7, CYAN);
     tft.drawRect(0, 300, tft.width(), 20, CYAN);
     tft.fillRect(0, 300,20 , 20, CYAN);
     tft.fillRect(220, 300,20,20, CYAN);
     
     

     tft.setCursor(20, 307);          
     tft.setTextColor(WHITE);
     tft.setTextSize(1);
     tft.print("<-slide for brush size ->");
     tft.setCursor(180, 307);
     tft.setTextColor(WHITE); 
     tft.print(PENRADIUS);
     tft.setTextSize(2);
     tft.setCursor(5,302);
     tft.setTextColor(BLACK);
     tft.print("?");
    
    
                tft.setCursor(BOXSIZE*5,10);
                tft.setTextSize(1);
                tft.setTextColor(BLACK);
                tft.print("GRID");

                tft.setCursor(0,BOXSIZE+1);
                tft.setTextSize(1);
                tft.setTextColor(BLACK);
                tft.print("GRID2");
    tft.drawRect(0, 0, BOXSIZE, BOXSIZE, WHITE);
    currentcolor = RED;
    M = '1';
    LOGO='1';

    
    PENRADIUS = 2;
    menu1();
    delay(1000);
    }

void loop()
{   

    uint16_t xpos, ypos;  //screen coordinates
    tp = ts.getPoint();   //tp.x, tp.y are ADC values

    // if sharing pins, you'll need to fix the directions of the touchscreen pins
    pinMode(XM, OUTPUT);
    pinMode(YP, OUTPUT);
    pinMode(XP, OUTPUT);
    pinMode(YM, OUTPUT);
    //    digitalWrite(XM, HIGH);
    //    digitalWrite(YP, HIGH);
    // we have some minimum pressure we consider 'valid'
    // pressure of 0 means no pressing!

    if (tp.z > MINPRESSURE && tp.z < MAXPRESSURE) {
        if (SwapXY != (Orientation & 1)) SWAP(tp.x, tp.y);
        xpos = map(tp.x, TS_LEFT, TS_RT, 0, tft.width());
        ypos = map(tp.y, TS_TOP, TS_BOT, 0, tft.height());
     
     
     Serial.print("ypos:"); // this code will help you get the y and x numbers for the touchscreen
     Serial.print(ypos);
     Serial.print("   xpos:");
     Serial.println(xpos);


 
     
        // This is The processing codes Dont Change it
        if (ypos < BOXSIZE) {               //draw white border on selected color box
            oldcolor = currentcolor;

            if (xpos < BOXSIZE) {
              
              PENRADIUS = 3;
                currentcolor = RED2;
                status1();
                
                tft.drawRect(0, 0, BOXSIZE, BOXSIZE, WHITE);
            } else if (xpos < BOXSIZE * 2) {
              
              PENRADIUS = 3;
                currentcolor = RED3;
                status1();
                
                 tft.drawRect(BOXSIZE*1, 0, BOXSIZE, BOXSIZE, WHITE);
            } else if (xpos < BOXSIZE * 3) {
              
              PENRADIUS = 3;
                currentcolor = ORANGE;
                status1();
                
                tft.drawRect(BOXSIZE * 2, 0, BOXSIZE, BOXSIZE, WHITE);
            } 
                 else if (xpos < BOXSIZE * 4) {
                 
                  PENRADIUS = 3;
                currentcolor = BROWN;
                status1();
                
                tft.drawRect(BOXSIZE * 3, 0, BOXSIZE, BOXSIZE, WHITE);
            } 
            else if (xpos < BOXSIZE *5 ) {
              
              PENRADIUS = 3;
                currentcolor = GOLD;
                status1();
                
                  tft.drawRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, WHITE);
            }
            
            else if (xpos < BOXSIZE * 6) {
              
              PENRADIUS = 3;
                currentcolor =LIME ;
                status1();
                
                  tft.drawRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, WHITE);
            }
            
            else if (xpos < BOXSIZE * 7) {
              
              PENRADIUS = 3;
                currentcolor = LIME2;
                status1();
                
                  tft.drawRect(BOXSIZE*6, 0, BOXSIZE, BOXSIZE, WHITE);
            }
            
            else if (xpos < BOXSIZE * 8) {
              
              PENRADIUS = 3;
                currentcolor = GREEN1;
                status1();
                
                  tft.drawRect(BOXSIZE*7, 0, BOXSIZE, BOXSIZE, WHITE);
            }
            
            else if (xpos < BOXSIZE * 9) {
              
              PENRADIUS = 3;
                currentcolor = GREEN2;
                status1();
                
                  tft.drawRect(BOXSIZE*8, 0, BOXSIZE, BOXSIZE, WHITE);
            }
            
            else if (xpos < BOXSIZE *10 ) {
              
              PENRADIUS = 3;
                currentcolor = GREEN3;
                status1();
                
                  tft.drawRect(BOXSIZE*9, 0, BOXSIZE, BOXSIZE, WHITE);
            }
            
            else if (xpos < BOXSIZE * 11) {
              
              PENRADIUS = 3;
                currentcolor = GREEN4;
                status1();
                
                  tft.drawRect(BOXSIZE*10, 0, BOXSIZE, BOXSIZE, WHITE);
            }
            
            else if (xpos < BOXSIZE *12 ) {
              
              PENRADIUS = 3;
                currentcolor = BLUE1;
                status1();
                
                  tft.drawRect(BOXSIZE*11, 0, BOXSIZE, BOXSIZE, WHITE);
            }
            
            else if (xpos < BOXSIZE *13 ) {
              
              PENRADIUS = 3;
                currentcolor = BLUE2;
                status1();
                
                  tft.drawRect(BOXSIZE*12, 0, BOXSIZE, BOXSIZE, WHITE);
            }
            
            else if (xpos < BOXSIZE *14 ) {
              
              PENRADIUS = 3;
                currentcolor = BLUE3;
                status1();
                
                  tft.drawRect(BOXSIZE*13, 0, BOXSIZE, BOXSIZE, WHITE);
            }
            
            else if (xpos < BOXSIZE * 15) {
              
              PENRADIUS = 3;
                currentcolor = BLUE4;
                status1();
                
                  tft.drawRect(BOXSIZE*14, 0, BOXSIZE, BOXSIZE, WHITE);
            }
            
            else if (xpos < BOXSIZE * 16) {
              
              PENRADIUS = 3;
                currentcolor = BLUE5;
                status1();
                
                  tft.drawRect(BOXSIZE*15, 0, BOXSIZE, BOXSIZE, WHITE);
            }
            
            else if (xpos < BOXSIZE * 17) {
              
              PENRADIUS = 3;
                currentcolor = BLUE6;
                status1();
                
                  tft.drawRect(BOXSIZE*16, 0, BOXSIZE, BOXSIZE, WHITE);
            }
            
            else if (xpos < BOXSIZE * 18) {
              
              PENRADIUS = 3;
                currentcolor = PURPUL1 ;
                status1();
                
                  tft.drawRect(BOXSIZE*17, 0, BOXSIZE, BOXSIZE, WHITE);
            }
            
            else if (xpos < BOXSIZE *19 ) {
              
              PENRADIUS = 3;
                currentcolor = PURPUL2;
                status1();
                
                  tft.drawRect(BOXSIZE*18, 0, BOXSIZE, BOXSIZE, WHITE);
            }
            
            else if (xpos < BOXSIZE * 20) {
              
              PENRADIUS = 3;
                currentcolor = PURPUL3;
                status1();
                
                  tft.drawRect(BOXSIZE*19, 0, BOXSIZE, BOXSIZE, WHITE);
            }
            
                        else if (xpos < BOXSIZE * 21) {
              
              PENRADIUS = 3;
                currentcolor = PINK1;
                status1();
                
                  tft.drawRect(BOXSIZE*20, 0, BOXSIZE, BOXSIZE, WHITE);
            }
                        
                        
                        else if (xpos < BOXSIZE * 22) {
              
              PENRADIUS = 3;
                currentcolor = PINK2;
                status1();
                
                  tft.drawRect(BOXSIZE*21, 0, BOXSIZE, BOXSIZE, WHITE);
            }
            
            else if (xpos < BOXSIZE * 23) {
             
                PENRADIUS = 6;
                currentcolor = BLACK;
                tft.drawRect(BOXSIZE * 22, 0, BOXSIZE, BOXSIZE, WHITE);
                tft.setCursor(BOXSIZE*18,10);
                tft.setTextSize(1);
                tft.setTextColor(WHITE);
                tft.print("eraser");
                status1();
        }   
            
            else if (xpos < BOXSIZE * 25) {
              currentcolor = WHITE;
                status1();
            }


             
        }
            if (oldcolor != currentcolor) { //rub out the previous white border
                if (oldcolor == RED2) tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED2);
                if (oldcolor == RED3) tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, RED3);
                if (oldcolor == ORANGE) tft.fillRect(BOXSIZE * 2, 0, BOXSIZE, BOXSIZE, ORANGE);
                if (oldcolor == BROWN) tft.fillRect(BOXSIZE * 3, 0, BOXSIZE, BOXSIZE, BROWN);
                if (oldcolor == GOLD) tft.fillRect(BOXSIZE * 4, 0, BOXSIZE, BOXSIZE, GOLD);
                if (oldcolor == LIME ) tft.fillRect(BOXSIZE * 5, 0, BOXSIZE, BOXSIZE, LIME);
                if (oldcolor == LIME2 ) tft.fillRect(BOXSIZE * 6, 0, BOXSIZE, BOXSIZE, LIME2);
                if (oldcolor ==  GREEN1) tft.fillRect(BOXSIZE * 7, 0, BOXSIZE, BOXSIZE, GREEN1);
                if (oldcolor ==  GREEN2) tft.fillRect(BOXSIZE * 8, 0, BOXSIZE, BOXSIZE, GREEN2);
                if (oldcolor ==  GREEN3) tft.fillRect(BOXSIZE * 9, 0, BOXSIZE, BOXSIZE,GREEN3 );
                if (oldcolor ==  GREEN4) tft.fillRect(BOXSIZE *10 , 0, BOXSIZE, BOXSIZE, GREEN4);
                if (oldcolor ==  BLUE1) tft.fillRect(BOXSIZE * 11, 0, BOXSIZE, BOXSIZE, BLUE1);
                if (oldcolor ==  BLUE2) tft.fillRect(BOXSIZE * 12, 0, BOXSIZE, BOXSIZE, BLUE2);
                if (oldcolor ==  BLUE3) tft.fillRect(BOXSIZE * 13, 0, BOXSIZE, BOXSIZE, BLUE3);
                if (oldcolor ==  BLUE4) tft.fillRect(BOXSIZE * 14, 0, BOXSIZE, BOXSIZE, BLUE4);
                if (oldcolor ==  BLUE5) tft.fillRect(BOXSIZE * 15, 0, BOXSIZE, BOXSIZE, BLUE5);
                if (oldcolor ==  BLUE6) tft.fillRect(BOXSIZE * 16, 0, BOXSIZE, BOXSIZE, BLUE6);
                if (oldcolor ==  PURPUL1) tft.fillRect(BOXSIZE *17 , 0, BOXSIZE, BOXSIZE, PURPUL1);
                if (oldcolor ==  PURPUL2) tft.fillRect(BOXSIZE *18 , 0, BOXSIZE, BOXSIZE, PURPUL2);
                if (oldcolor ==  PURPUL3) tft.fillRect(BOXSIZE *19 , 0, BOXSIZE, BOXSIZE, PURPUL3);
                if (oldcolor ==  PINK1) tft.fillRect(BOXSIZE *20 , 0, BOXSIZE, BOXSIZE,PINK1 );
                if (oldcolor ==  PINK2) tft.fillRect(BOXSIZE *22 , 0, BOXSIZE, BOXSIZE, PINK2);
                if (oldcolor ==  BLACK) tft.fillRect(BOXSIZE *22 , 0, BOXSIZE, BOXSIZE, BLACK);
                if (oldcolor == WHITE) tft.fillRect(BOXSIZE * 23, 0, BOXSIZE, BOXSIZE, WHITE);

                if (oldcolor == CYAN) {
                                      tft.drawRect(0, 300, tft.width(), 20, CYAN);
                                      tft.fillRect(0, 300,20 , 20, CYAN);
                                      tft.fillRect(220, 300,20,20, CYAN);
                                      tft.fillRect(20, 301,200,20, BLACK);
                                      tft.setCursor(20, 307);
                                      tft.setTextSize(1);
                                      tft.setTextColor(WHITE);
                                      tft.print("<-slide for brush size ->");

                                      tft.setCursor(180, 307);
                                      tft.setTextSize(1);
                                      tft.setTextColor(WHITE);
                                      tft.print(PENRADIUS);}

                                      tft.setTextSize(2);
                                      tft.setCursor(5,302);
                                      tft.setTextColor(BLACK);
                                      tft.print("?");
    
            }

            if(ypos > 292 && ypos < 302 && xpos>3 && xpos<18 ){
              PENRADIUS = 1;
              LOGO='1';
              
                                      tft.drawRect(0, 300, tft.width(), 20, CYAN);
                                      tft.fillRect(0, 300,20 , 20, CYAN);
                                      tft.fillRect(220, 300,20,20, CYAN);
                                      tft.fillRect(20, 301,200,20, BLACK);
                                      tft.setCursor(20, 307);
                                      tft.setTextColor(WHITE);
                                      tft.setTextSize(1);
                                      tft.print("<-slide for brush size ->");

                                      tft.setCursor(180, 307);
                                      tft.setTextColor(WHITE);
                                      tft.setTextSize(1);
                                      tft.print(PENRADIUS);
            }
            if(ypos > 290 && ypos < 304 && xpos>19 && xpos<49 ){
              PENRADIUS = 2;

              LOGO='2';
                                      tft.drawRect(0, 300, tft.width(), 20, CYAN);
                                      tft.fillRect(0, 300,20 , 20, CYAN);
                                      tft.fillRect(220, 300,20,20, CYAN);
                                      tft.fillRect(20, 301,200,20, BLACK);
                                      tft.setTextSize(1);
                                      tft.setCursor(20, 307);
                                      tft.setTextColor(WHITE);
                                      tft.print("<-slide for brush size ->");

                                      tft.setCursor(180, 307);
                                      tft.setTextSize(1);
                                      tft.setTextColor(WHITE);
                                      tft.print(PENRADIUS);
            }            
            if(ypos > 290 && ypos < 304 && xpos>50 && xpos<80 ){
              PENRADIUS = 3;

              LOGO='3';
                                      tft.drawRect(0, 300, tft.width(), 20, CYAN);
                                      tft.fillRect(0, 300,20 , 20, CYAN);
                                      tft.fillRect(220, 300,20,20, CYAN);
                                      tft.fillRect(20, 301,200,20, BLACK);
                                      tft.setCursor(20, 307);
                                      tft.setTextColor(WHITE);
                                      tft.setTextSize(1);
                                      tft.print("<-slide for brush size ->");

                                      tft.setCursor(180, 307);
                                      tft.setTextSize(1);
                                      tft.setTextColor(WHITE);
                                      tft.print(PENRADIUS);
            }
                        
            if(ypos > 290 && ypos < 304 && xpos>80 && xpos<110 ){
              PENRADIUS = 4;

              LOGO='4';
                                      tft.drawRect(0, 300, tft.width(), 20, CYAN);
                                      tft.fillRect(0, 300,20 , 20, CYAN);
                                      tft.fillRect(220, 300,20,20, CYAN);
                                      tft.fillRect(20, 301,200,20, BLACK);
                                      tft.setCursor(20, 307);
                                      tft.setTextColor(WHITE);
                                      tft.setTextSize(1);
                                      tft.print("<-slide for brush size ->");

                                      tft.setCursor(180, 307);
                                      tft.setTextSize(1);
                                      tft.setTextColor(WHITE);
                                      tft.print(PENRADIUS);
            }
                        
            
            if(ypos > 290 && ypos < 304 && xpos>112 && xpos<145 ){
              PENRADIUS = 6;

              LOGO='5';
                                      tft.drawRect(0, 300, tft.width(), 20, CYAN);
                                      tft.fillRect(0, 300,20 , 20, CYAN);
                                      tft.fillRect(220, 300,20,20, CYAN);
                                      tft.fillRect(20, 301,200,20, BLACK);
                                      tft.setCursor(20, 307);
                                      tft.setTextColor(WHITE);
                                      tft.setTextSize(1);
                                      tft.print("<-slide for brush size ->");

                                      tft.setCursor(180, 307);
                                      tft.setTextColor(WHITE);
                                      tft.setTextSize(1);
                                      tft.print(PENRADIUS);
            }

            
            if(ypos > 290 && ypos < 304 && xpos>145 && xpos<180 ){
              PENRADIUS = 7;
              LOGO='6';



               tft.drawRect(0, 300, tft.width(), 20, CYAN);
                                      tft.fillRect(0, 300,20 , 20, CYAN);
                                      tft.fillRect(220, 300,20,20, CYAN);
                                      tft.fillRect(20, 301,200,20, BLACK);
                                      tft.setCursor(20, 307);
                                      tft.setTextColor(WHITE);
                                      tft.setTextSize(1);
                                      tft.print("<-slide for brush size ->");

                                      tft.setCursor(180, 307);
                                      tft.setTextColor(WHITE);
                                      tft.setTextSize(1);
                                      tft.print(PENRADIUS);
            }

            if(ypos > 290 && ypos < 304 && xpos>181 && xpos<214 ){
             PENRADIUS = 8;
             LOGO='7';

              
                                   
                                      tft.drawRect(0, 300, tft.width(), 20, CYAN);
                                      tft.fillRect(0, 300,20 , 20, CYAN);
                                      tft.fillRect(220, 300,20,20, CYAN);
                                      tft.fillRect(20, 301,200,20, BLACK);
                                      tft.setTextSize(1);
                                      tft.setCursor(20, 307);
                                      tft.setTextColor(WHITE);
                                      tft.print("<-slide for brush size ->");

                                      tft.setCursor(180, 307);
                                      tft.setTextSize(1);
                                      tft.setTextColor(WHITE);
                                      tft.print(PENRADIUS);
            }


            





            

                      
              if (ypos > 275 && ypos <284 && xpos>197 && xpos<239 ) {
               M='1';
              }
                      
                       
              else if ( ypos > 279 && ypos <288 && xpos>153 && xpos<195 ) {
              
              M='2';
              
              }
              else if ( ypos > 279 && ypos <288 && xpos>111 && xpos<150 ) {
              
              M='3';
              
              }
             
              //Game Corner
              else if ( ypos > 279 && ypos <288 && xpos>65 && xpos<108 ) {
               
                             if (LOGO == '1'){
                              
                              tft.fillRect(20,50,180,170,BLUE);
                              tft.setCursor(80,85);
                              tft.setTextSize(19);
                              tft.setTextColor(WHITE);                             
                              tft.print("f");}
                              else if (LOGO =='2'){

                              tft.fillCircle(120,170,80,WHITE);
                              tft.fillRect(68,201,50,42,WHITE);
                              tft.fillCircle(121,171,74,GREEN3);
                              tft.fillRect(71,201,50,37,GREEN3);
                              }
                              else if (LOGO =='3'){
                                tft.fillRoundRect(30,112,180,110,20,RED);
                              }
                              else if (LOGO == '4'){
                                tft.setCursor(84,140);
                                tft.setTextSize(4);
                                tft.setTextColor(RED);
                                tft.print("O");
                              }
                              }
               
                              
              else if ( ypos > 279 && ypos <288 && xpos>23 && xpos<63 ) {


                               tft.fillRect(39, 15, 200, 24, BLACK);
             tft.setCursor(39,15);
             tft.setTextSize(3);
             tft.setTextColor(WHITE);
             tft.print("WORD GAME");
  tft.fillRect(78, 40, 4, 200, WHITE);
  tft.fillRect(39, 40, 4, 200, WHITE);
  tft.fillRect(117, 40, 4, 300, WHITE);
  tft.fillRect(197, 40, 4, 200, WHITE);
  tft.fillRect(158, 40, 4, 200, WHITE);
  tft.fillRect(0, 78,240, 4, WHITE);
  tft.fillRect(0, 39,240, 4, WHITE);
  tft.fillRect(0, 117,240, 4, WHITE);
  tft.fillRect(0, 197,240, 4, WHITE);
  tft.fillRect(0, 236,240, 4, WHITE);
  tft.fillRect(0, 301,240, 4, WHITE);

  tft.fillRect(0, 158, 240, 4, WHITE);
status1;

              }
              else if( ypos > 279 && ypos <288 && xpos>0 && xpos<23 ) {
              
              

              
   tft.fillRect(39, 15, 200, 24, BLACK);
             tft.setCursor(39,15);
             tft.setTextSize(3);
             tft.setTextColor(WHITE);
             tft.print("TIC TAC TOE");
           
             
  tft.fillRect(78, 40, 4, 240, WHITE);
  tft.fillRect(158, 40, 4, 240, WHITE);
  tft.fillRect(0, 39, 240,4, WHITE);
  tft.fillRect(0, 117,240, 4, WHITE);
  tft.fillRect(0, 197, 240, 4, WHITE);
  tft.fillRect(0, 390, 240, 4, WHITE);
              status1;
              


              }
                     

            
            //how to use it
            if (ypos > 291 && ypos <304 && xpos>65517 && xpos<65531 ) {
              help();              
            }
    
        // are we in drawing area ?
        if (((ypos - PENRADIUS) > BOXSIZE) && ((ypos + PENRADIUS) < tft.height()-40) ) {
            
            if(M=='1'){
              tft.fillCircle((xpos+9), (ypos+7), PENRADIUS, currentcolor);
            }
            else if(M=='2'){
              tft.drawCircle(xpos,ypos,(PENRADIUS*20),currentcolor);
            }
            else if(M=='3'){
              tft.drawRect(xpos, ypos,20*PENRADIUS ,20*PENRADIUS , currentcolor);
            } 
            
         }

        
        // Clear Button
        if (ypos > 288 && ypos <302 && xpos>225 && xpos<241 ) {
            // press the Lower-Right Corner of the screen to Clear
            menu1();
            tft.fillRect(0, 0, tft.width(), tft.height() , BLACK);
    tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED2);
    tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, RED3);
    tft.fillRect(BOXSIZE * 2, 0, BOXSIZE, BOXSIZE, ORANGE);
    tft.fillRect(BOXSIZE * 3, 0, BOXSIZE, BOXSIZE, BROWN);
    tft.fillRect(BOXSIZE * 4, 0, BOXSIZE, BOXSIZE, GOLD);
    tft.fillRect(BOXSIZE * 5, 0, BOXSIZE, BOXSIZE, LIME);
    tft.fillRect(BOXSIZE * 6, 0, BOXSIZE, BOXSIZE, LIME2);
    tft.fillRect(BOXSIZE * 7, 0, BOXSIZE, BOXSIZE, GREEN1);
    tft.fillRect(BOXSIZE * 8, 0, BOXSIZE, BOXSIZE, GREEN2);
    tft.fillRect(BOXSIZE * 9, 0, BOXSIZE, BOXSIZE, GREEN3);
    tft.fillRect(BOXSIZE * 10, 0, BOXSIZE, BOXSIZE, GREEN4);
    tft.fillRect(BOXSIZE * 11, 0, BOXSIZE, BOXSIZE, BLUE1);
    tft.fillRect(BOXSIZE * 12, 0, BOXSIZE, BOXSIZE, BLUE2);
    tft.fillRect(BOXSIZE * 13, 0, BOXSIZE, BOXSIZE, BLUE3);
    tft.fillRect(BOXSIZE * 14, 0, BOXSIZE, BOXSIZE, BLUE4);
    tft.fillRect(BOXSIZE * 15, 0, BOXSIZE, BOXSIZE, BLUE5);
    tft.fillRect(BOXSIZE * 16, 0, BOXSIZE, BOXSIZE, BLUE6);
    tft.fillRect(BOXSIZE * 17, 0, BOXSIZE, BOXSIZE, PURPUL1);
    tft.fillRect(BOXSIZE * 18, 0, BOXSIZE, BOXSIZE, PURPUL2);
    tft.fillRect(BOXSIZE * 19, 0, BOXSIZE, BOXSIZE, PURPUL3);
    tft.fillRect(BOXSIZE * 20, 0, BOXSIZE, BOXSIZE, PINK1);
    tft.fillRect(BOXSIZE * 21, 0, BOXSIZE, BOXSIZE, PINK2);
    tft.fillRect(BOXSIZE * 22, 0, BOXSIZE, BOXSIZE, BLACK);
    tft.fillRect(BOXSIZE * 23, 0, BOXSIZE, BOXSIZE, WHITE);
    
    

            
                                      tft.drawRect(0, 300, tft.width(), 20, CYAN);
                                      tft.fillRect(0, 300,20 , 20, CYAN);
                                      tft.fillRect(220, 300,20,20, CYAN);
                                      tft.fillRect(20, 301,200,20, BLACK);
                                      tft.setCursor(20, 307);
                                      tft.setTextSize(1);
                                      tft.setTextColor(WHITE);
                                      tft.print("<-slide for brush size ->");

                                      tft.setCursor(180, 307);
                                      tft.setTextSize(1);
                                      tft.setTextColor(WHITE);
                                      tft.print(PENRADIUS);

                                                  tft.setTextSize(2);
     tft.setCursor(5,302);
     tft.setTextColor(BLACK);
     tft.print("?");
        }
    }
}

  void drawStartScreen()
{
   tft.fillScreen(BLACK);
  
  //Draw white frame
  tft.drawRect(0,0,240,320,YELLOW);
       //Print "Tic Tac Toe" Text
  tft.setCursor(19,20);
  tft.setTextColor(RED);
  tft.setTextSize(4);
  tft.print("STARTING.");
  delay(800);
    //Print "Tic Tac Toe" Text
  tft.setCursor(19,80);
  tft.setTextColor(BLUE);
  tft.setTextSize(3.9);
  tft.print("painting");

    tft.setCursor(19,80);
  tft.setTextColor(GREEN);
  tft.setTextSize(3.9);
  tft.print("    ");

    tft.setCursor(19,80);
  tft.setTextColor(GREEN);
  tft.setTextSize(3.9);
  tft.print("        ");
  delay(800);
  //Print "Tic Tac Toe" Text
  tft.setCursor(30,140);
  tft.setTextColor(WHITE);
  tft.setTextSize(4);
  tft.print("By Areeb");
  }

void drawboard2(){
  tft.fillRect(78, BOXSIZE*2, 4, 240, WHITE);
  tft.fillRect(158, BOXSIZE*2, 4, 240, WHITE);
  tft.fillRect(0, 78, 240,4, WHITE);
  tft.fillRect(0, 236,240, 4, WHITE);
  tft.fillRect(0, 158, 240, 4, WHITE);
}
  void drawboard() {
  tft.fillRect(78, BOXSIZE, 4, 314, WHITE);
  tft.fillRect(39, BOXSIZE, 4, 314, WHITE);
  tft.fillRect(117, BOXSIZE, 4, 314, WHITE);
  tft.fillRect(197, BOXSIZE, 4, 314, WHITE);
  tft.fillRect(158, BOXSIZE, 4, 314, WHITE);
  tft.fillRect(0, 78,240, 4, WHITE);
  tft.fillRect(0, 39,240, 4, WHITE);
  tft.fillRect(0, 117,240, 4, WHITE);
  tft.fillRect(0, 197,240, 4, WHITE);
  tft.fillRect(0, 236,240, 4, WHITE);
  tft.fillRect(0, 275,240, 4, WHITE);
  tft.fillRect(0, 314,240, 4, WHITE);
  tft.fillRect(0, 158, 240, 4, WHITE);
  }
void status1() {

   tft.drawRect(0, 300, tft.width(), 20, CYAN);
                                      tft.fillRect(0, 300,20 , 20, CYAN);
                                      tft.fillRect(220, 300,20,20, CYAN);
                                      tft.fillRect(20, 301,200,20, currentcolor);
                                      tft.setTextSize(1);
                                      tft.setCursor(20, 307);
                                      tft.setTextColor(WHITE);
                                      tft.print("<-slide for brush size ->");
                                      
                                      tft.setTextSize(1);
                                      tft.setCursor(180, 307);
                                      tft.setTextColor(WHITE);
                                      tft.print(PENRADIUS);
}

void help(){
  tft.fillRect(0, BOXSIZE, tft.width(), tft.height() - (BOXSIZE+20), BLACK);
                                       
                                      tft.setTextSize(2);
                                      tft.setCursor(0, 20);
                                      tft.setTextColor(WHITE);
                                      tft.print("<-Change the color->");

                                      tft.setTextSize(2);
                                      tft.setCursor(30, 50);
                                      tft.setTextColor(WHITE);
                                      tft.print("by sliding here");

                                      delay(3000);


                                      tft.setTextSize(2);
                                      tft.setCursor(30, 240);
                                      tft.setTextColor(WHITE);
                                      tft.print("by sliding here ");
                                      
                                      tft.setTextSize(2);
                                      tft.setCursor(10, 270);
                                      tft.setTextColor(WHITE);
                                      tft.print("<-Change pen size->");

                                      delay(3000);
                                      tft.fillRect(0, BOXSIZE, tft.width(), tft.height() - (BOXSIZE+20), BLACK);
                                      


                                      tft.setTextSize(2);
                                      tft.setCursor(0, 270);
                                      tft.setTextColor(WHITE);
                                      tft.drawLine(4,260,4,278,WHITE);
                                      tft.print("V-HELP");

                                      delay(1000);
                                      
                                      tft.setTextSize(2);
                                      tft.setCursor(152, 270);
                                      tft.setTextColor(WHITE);
                                      tft.drawLine(228,260,228,278,WHITE);
                                      tft.print("CLEAR-V");
        
                                       delay(2000);
                                       tft.fillRect(0, BOXSIZE, tft.width(), tft.height() - (BOXSIZE+20), BLACK);
                                       menu1();
                                      tft.setTextSize(2);
                                      tft.setCursor(0, 20);
                                      tft.setTextColor(WHITE);
                                      tft.print("   For Games like   ");

                                      

                                     tft.setTextSize(1);
                                      tft.setCursor(2, 270);
                                      tft.setTextColor(WHITE);
                                      tft.drawLine(4,260,4,270,WHITE);
                                      tft.print("V- GAMES");

                                      delay(1000);


                                      
                                      tft.setTextSize(1);
                                      tft.setCursor(52, 270);
                                      tft.setTextColor(WHITE);
                                      tft.drawLine(60,260,60,270,WHITE);
                                      tft.print("-V-");
        

                                      tft.setTextSize(1);
                                      tft.setCursor(92, 270);
                                      tft.setTextColor(WHITE);
                                      tft.drawLine(100,260,100,270,WHITE);
                                      tft.print("-V");
        

                                      
                                      tft.setTextSize(2);
                                      tft.setCursor(30, 50);
                                      tft.setTextColor(WHITE);
                                      tft.print("i>TIC TAC TOE");

                                      
                                      tft.setTextSize(2);
                                      tft.setCursor(30, 80);
                                      tft.setTextColor(WHITE);
                                      tft.print("ii>WORD GAME");

                                      
                                      tft.setTextSize(2);
                                      tft.setCursor(15, 110);
                                      tft.setTextColor(WHITE);
                                      tft.print("iii>Complete Logo");

                                      
                                      tft.setTextSize(2);
                                      tft.setCursor(20, 140);
                                      tft.setTextColor(WHITE);
                                      tft.print("Click near Arrow");

                                      delay(5000);
                                      tft.fillRect(0, BOXSIZE, tft.width(), tft.height() - (BOXSIZE+20), BLACK);
                                      menu1();

                                      tft.setTextSize(2);
                                      tft.setCursor(0, 20);
                                      tft.setTextColor(WHITE);
                                      tft.print("SELECT SHAPES");

                                      tft.drawLine(140,230,140,290,WHITE);
                                      tft.drawLine(120,230,140,230,WHITE);
                                      tft.setTextSize(2);
                                      tft.setCursor(50, 220);
                                      tft.setTextColor(YELLOW);
                                      tft.print("SQUARE");
                                      delay(600);
                                      
                                      tft.drawLine(180,170,180,290,WHITE);
                                      tft.drawLine(140,170,180,170,WHITE);
                                      tft.setTextSize(2);
                                      tft.setCursor(63, 160);
                                      tft.setTextColor(PURPUL1);
                                      tft.print("CIRCLE");
                                      delay(600);
                                      
                                      tft.drawLine(220,110,220,290,WHITE);
                                      tft.drawLine(180,110,220,110,WHITE);
                                      tft.setTextSize(2);
                                      tft.setCursor(137, 100);
                                      tft.setTextColor(BROWN);
                                      tft.print("LINE");
                                      delay(600);
                                      

delay(2000);

                                      tft.fillRect(0, BOXSIZE, tft.width(), tft.height() - (BOXSIZE+20), BLACK);
                                      menu1();

                                      tft.setTextSize(2);
                                      tft.setCursor(10, 110);
                                      tft.setTextColor(WHITE);
                                      tft.print("NOW START PAINTING");

                                      tft.setTextSize(2);
                                      tft.setCursor(40, 140);
                                      tft.setTextColor(WHITE);
                                      tft.print("  in 3 second");


                                      delay(1000);
                                     
                                      
tft.fillRect(0, BOXSIZE, tft.width(), tft.height() - (BOXSIZE+20), BLACK);
menu1();
                                      tft.setTextSize(2);
                                      tft.setCursor(10, 110);
                                      tft.setTextColor(WHITE);
                                      tft.print("NOW START PAINTING");

                                      tft.setTextSize(2);
                                      tft.setCursor(40, 140);
                                      tft.setTextColor(WHITE);
                                      tft.print("  in 2 second");

                                      delay(1000);
                                     
                                      
tft.fillRect(0, BOXSIZE, tft.width(), tft.height() - (BOXSIZE+20), BLACK);
menu1();
                                      tft.setTextSize(2);
                                      tft.setCursor(10, 110);
                                      tft.setTextColor(WHITE);
                                      tft.print("NOW START PAINTING");

                                      tft.setTextSize(2);
                                      tft.setCursor(40, 140);
                                      tft.setTextColor(WHITE);
                                      tft.print("  in 1 second");

                                      delay(1000);
                                     
                                      
tft.fillRect(0, BOXSIZE, tft.width(), tft.height() - (BOXSIZE+20), BLACK);
menu1();
                                      tft.setTextSize(6);
                                      tft.setCursor(20, 110);
                                      tft.setTextColor(WHITE);
                                      tft.print("PAINT!");

                                      delay(700);
                                      
                                      tft.fillRect(0, BOXSIZE, tft.width(), tft.height() - (BOXSIZE+20), BLACK);
                                      menu1();
}



void menu1(){
  tft.fillRect(0, 290,40 , 10, RED);
  tft.fillRect(40, 290,80 , 10, BLUE);
  tft.fillRect(80, 290,120 , 10, GREEN);
  tft.fillRect(120, 290,160 , 10, YELLOW);
  tft.fillRect(160, 290,200 , 10, PURPUL1);
  tft.fillRect(200, 290,240 , 10, ORANGE);
}




If you Read The Code Carefully It will be Easy to understand how it works


So Lets Test It


If it is not Working or You Have Any Problem Comment Below or Contact Me Via My FaceBook Page @Diyareeb

Comments

Popular posts from this blog

How to use TV as Arduino display || Arduino TVout Library || Hindi

Making food is easy now || Supercook.com

Arduino Keypad