Here's a sketch for using a 2.4'' touchscreen without any library. This is necessary since the Utouch-lib needs the IRQ-pin which isn't provided on some shields: here PIN 10 uses the CS-signal. Remember to check, which minimal x- any y-values your screen provides on 'touch'-events (see code remarks below):

#define LCD_RS   19         
#define LCD_WR   18     
#define LCD_CS   17       
#define LCD_REST 16

#define DCLK     15
#define DIN      14 
#define CS       10  
#define DOUT     8

//#define IRQ      7    

unsigned int TP_X,TP_Y,x0,y0;    
unsigned int l3=0;
int lx,ly, l2, ry,rx,x3=65,y3=318;
int  k=3, vh2=0x84,vl2=0xFF;



void spistar()                                     //SPI Start
{
  digitalWrite(CS,LOW);
  digitalWrite(DCLK,HIGH);
  digitalWrite(DIN,HIGH);
  digitalWrite(DCLK,HIGH);

}
//**********************************************************
void WriteCharTo7843(unsigned char num)          //SPI Write Data - works also with TCS2046
{
  unsigned char count=0;
  unsigned char temp;
  unsigned nop;
  temp=num;
  digitalWrite(DCLK,LOW);
  for(count=0;count<8;count++)
  {
    if(temp&0x80)
      digitalWrite(DIN,HIGH);
    else
      digitalWrite(DIN,LOW);

    temp=temp<<1; 

    digitalWrite(DCLK,LOW);                
    nop++;
    nop++;
    digitalWrite(DCLK,HIGH);
    nop++;
    nop++;
  }
}

//**********************************************************
unsigned int ReadFromCharFrom7843()             //SPI Read Data
{ 
  unsigned nop;
  unsigned char count=0;
  unsigned int Num=0;
  for(count=0;count<12;count++)
  {
    Num<<=1;
    digitalWrite(DCLK,HIGH);//DCLK=1; _nop_();_nop_();_nop_();                
    nop++;
    digitalWrite(DCLK,LOW);//DCLK=0; _nop_();_nop_();_nop_();
    nop++;
    if(digitalRead(DOUT)) Num++;
  }
  return(Num);
}



void LCD_Writ_Bus(char VH,char VL)   
{   
  PORTD = VH;
  digitalWrite(LCD_WR,LOW);
  digitalWrite(LCD_WR,HIGH);
  PORTD = VL;
  digitalWrite(LCD_WR,LOW);
  digitalWrite(LCD_WR,HIGH);
}


void LCD_Write_COM(char VH,char VL)  
{   
  digitalWrite(LCD_RS,LOW);
  LCD_Writ_Bus(VH,VL);
}


void LCD_Write_DATA(char VH,char VL)    
{
  digitalWrite(LCD_RS,HIGH);
  LCD_Writ_Bus(VH,VL);
}

void Lcd_Write_Com_Data(int com,int val)
{
    LCD_Write_COM(com>>8,com);
    LCD_Write_DATA(val>>8,val);
}

void Address_set(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2)
{
  LCD_Write_COM(0x00,0x46);LCD_Write_DATA(x2,x1);	  
  LCD_Write_COM(0x00,0x47);LCD_Write_DATA(y2>>8,y2);  
  LCD_Write_COM(0x00,0x48);LCD_Write_DATA(y1>>8,y1);
  LCD_Write_COM(0x00,0x20);LCD_Write_DATA(x1>>8,x1);	  
  LCD_Write_COM(0x00,0x21);LCD_Write_DATA(y1>>8,y1); 
  LCD_Write_COM(0x00,0x22);		         				 
}

void LCD_Init(void)
{

  digitalWrite(LCD_REST,HIGH);
  delay(5); 
  digitalWrite(LCD_REST,LOW);
  delay(5);
  digitalWrite(LCD_REST,HIGH);
  delay(5);

  digitalWrite(LCD_CS,LOW);  
        Lcd_Write_Com_Data(0x11,0x2004);		
        Lcd_Write_Com_Data(0x13,0xCC00);		
        Lcd_Write_Com_Data(0x15,0x2600);	
	Lcd_Write_Com_Data(0x14,0x252A);			
	Lcd_Write_Com_Data(0x12,0x0033);		
	Lcd_Write_Com_Data(0x13,0xCC04);		
	delay(1); 
	Lcd_Write_Com_Data(0x13,0xCC06);		
	delay(1); 
	Lcd_Write_Com_Data(0x13,0xCC4F);		
	delay(1); 
	Lcd_Write_Com_Data(0x13,0x674F);
	Lcd_Write_Com_Data(0x11,0x2003);
	delay(1); 	
	Lcd_Write_Com_Data(0x30,0x2609);		
	Lcd_Write_Com_Data(0x31,0x242C);		
	Lcd_Write_Com_Data(0x32,0x1F23);		
	Lcd_Write_Com_Data(0x33,0x2425);		
	Lcd_Write_Com_Data(0x34,0x2226);		
	Lcd_Write_Com_Data(0x35,0x2523);		
	Lcd_Write_Com_Data(0x36,0x1C1A);		
	Lcd_Write_Com_Data(0x37,0x131D);		
	Lcd_Write_Com_Data(0x38,0x0B11);		
	Lcd_Write_Com_Data(0x39,0x1210);		
	Lcd_Write_Com_Data(0x3A,0x1315);		
	Lcd_Write_Com_Data(0x3B,0x3619);		
	Lcd_Write_Com_Data(0x3C,0x0D00);		
	Lcd_Write_Com_Data(0x3D,0x000D);		
	Lcd_Write_Com_Data(0x16,0x0007);		
	Lcd_Write_Com_Data(0x02,0x0013);		
	Lcd_Write_Com_Data(0x03,0x0003);		
	Lcd_Write_Com_Data(0x01,0x0127);		
	delay(1); 
	Lcd_Write_Com_Data(0x08,0x0303);		
	Lcd_Write_Com_Data(0x0A,0x000B);		
	Lcd_Write_Com_Data(0x0B,0x0003);   
	Lcd_Write_Com_Data(0x0C,0x0000);   
	Lcd_Write_Com_Data(0x41,0x0000);    
	Lcd_Write_Com_Data(0x50,0x0000);   
	Lcd_Write_Com_Data(0x60,0x0005);    
        Lcd_Write_Com_Data(0x70,0x000B);    
	Lcd_Write_Com_Data(0x71,0x0000);    
	Lcd_Write_Com_Data(0x78,0x0000);    
	Lcd_Write_Com_Data(0x7A,0x0000);   
	Lcd_Write_Com_Data(0x79,0x0007);		
	Lcd_Write_Com_Data(0x07,0x0051);   
	delay(1); 	
	Lcd_Write_Com_Data(0x07,0x0053);		
	Lcd_Write_Com_Data(0x79,0x0000);

	LCD_Write_COM(0x00,0x22);
        digitalWrite(LCD_CS,HIGH);  

}

void Pant(char VH,char VL)
{
  int i,j;
  Address_set(0,0,240,320);
  for(i=0;i<=320;i++)
  {
    for (j=0;j<=240;j++)
    {
      LCD_Write_DATA(VH,VL);
    }
  }
}

void digi(int z3)         //print digits indicating the color-code (2 x 0-255) to paint (increased on touch)
{
  unsigned char p;
  int x2, y2, z2, i,h2=1000;
  digitalWrite(LCD_CS,LOW); 
  for(i=0;i<3;i++)
  {
    y2=y3;
    x2=x3+(10*i);
    Address_set(x2+6,y2-15,x2+7,y2);
    for(p=0; p<32; p++)  LCD_Write_DATA(0xFF,0xFF); 
    Address_set(x2,y2-15,x2+7,y2-14);
    for(p=0; p<16; p++)  LCD_Write_DATA(0xFF,0xFF);
    Address_set(x2,y2-1,x2+7,y2);
    for(p=0; p<16; p++)  LCD_Write_DATA(0xFF,0xFF);
    Address_set(x2,y2-8,x2+7,y2-7);
    for(p=0; p<16; p++)  LCD_Write_DATA(0xFF,0xFF);
    Address_set(x2,y2-15,x2+1,y2);
    for(p=0; p<32; p++)  LCD_Write_DATA(0xFF,0xFF);

    h2=h2/10;
    z2=z3/h2; 
    z3=z3-z2*h2;
    if (z2==0)  {
      Address_set(x2+2,y2-8,x2+5,y2-7);
      for(p=0; p<8; p++)  LCD_Write_DATA(0x00,0x00);
    }
    if (z2==1)  {
      Address_set(x2,y2-15,x2+5,y2);
      for(p=0; p<96; p++)  LCD_Write_DATA(0x00,0x00);
    }
    if (z2==2)  {
      Address_set(x2,y2-13,x2+1,y2-9);
      for(p=0; p<10; p++)  LCD_Write_DATA(0x00,0x00);
      Address_set(x2+6,y2-6,x2+7,y2-2);
      for(p=0; p<10; p++)  LCD_Write_DATA(0x00,0x00);
    }
    if (z2==3)  {
      Address_set(x2,y2-13,x2+1,y2-9);
      for(p=0; p<10; p++)  LCD_Write_DATA(0x00,0x00);
      Address_set(x2,y2-6,x2+1,y2-2);
      for(p=0; p<10; p++)  LCD_Write_DATA(0x00,0x00);
    }
    if (z2==4)  {
      Address_set(x2,y2-6,x2+5,y2);
      for(p=0; p<42; p++)  LCD_Write_DATA(0x00,0x00);
      Address_set(x2+2,y2-15,x2+5,y2-14);
      for(p=0; p<8; p++)  LCD_Write_DATA(0x00,0x00);
    }
    if (z2==5)  {
      Address_set(x2+6,y2-13,x2+7,y2-9);
      for(p=0; p<10; p++)  LCD_Write_DATA(0x00,0x00);
     Address_set(x2,y2-6,x2+1,y2-2);
      for(p=0; p<10; p++)  LCD_Write_DATA(0x00,0x00);
    }
    if (z2==6)  {
      Address_set(x2+6,y2-13,x2+7,y2-9);
      for(p=0; p<10; p++)  LCD_Write_DATA(0x00,0x00);
    }
    if (z2==7)  {
      Address_set(x2,y2-13,x2+5,y2);
      for(p=0; p<84; p++)  LCD_Write_DATA(0x00,0x00);
    }
    if (z2==9)  {
      Address_set(x2,y2-6,x2+1,y2-2);
      for(p=0; p<10; p++)  LCD_Write_DATA(0x00,0x00);
    }
  }
  digitalWrite(LCD_CS,HIGH); 
}

void newpa(void)                              //paint the frame
{
  unsigned char p;
  digitalWrite(LCD_CS,LOW); 
  Pant(0x00,0x00);   

  Address_set(0,319,240,319);
  for(p=0; p<240; p++)  LCD_Write_DATA(0xF8,0x00);
  Address_set(0,0,240,0);
  for(p=0; p<240; p++)  LCD_Write_DATA(0xFF,0xFF);
  Address_set(0,300,240,300);
  for(p=0; p<240; p++)  LCD_Write_DATA(0xFF,0xFF);
  Address_set(0,0,0,255);
  for(p=0; p<255; p++)  LCD_Write_DATA(0xF8,0x00);
  Address_set(0,255,0,300);
  for(p=0; p<45; p++)  LCD_Write_DATA(0xF8,0x00);
  Address_set(239,0,239,255);
  for(p=0; p<255; p++)  LCD_Write_DATA(0xF8,0x00);
  Address_set(239,255,239,300);
  for(p=0; p<45; p++)  LCD_Write_DATA(0xF8,0x00);
  Address_set(50,308,59,311);
  for(p=0; p<40; p++)  LCD_Write_DATA(0x07,0xE0);
  Address_set(53,305,56,314);
  for(p=0; p<40; p++)  LCD_Write_DATA(0x07,0xE0);
  Address_set(215,305,239,314);
  for(p=0; p<250; p++)  LCD_Write_DATA(0xF8,0x00);
  digitalWrite(LCD_CS,HIGH); 


}

 void recan(void)                            //status bar for painting size and example of selected color
{
  int i,j;
 digitalWrite(LCD_CS,LOW); 
  for(i=0;i<7;i++)
  {
    Address_set(i*5,305,i*5+3,314);
    for(j=0; j<40; j++)
    {
      if (1+i*2<= k) LCD_Write_DATA(0xFF,0xE0); else LCD_Write_DATA(0x00,0x00);
    }
 }
Address_set(100,305,124,314);
  for(i=0; i<250; i++)  LCD_Write_DATA(vh2,vl2);
Address_set(125,305,149,314);
  for(i=0; i<250; i++)  LCD_Write_DATA(vh2,vl2);
 digitalWrite(LCD_CS,HIGH); 
}


void AD7843(void)              
{
  digitalWrite(CS,LOW);                    
  WriteCharTo7843(0x90);        
  digitalWrite(DCLK,HIGH);
  digitalWrite(DCLK,LOW); 
  TP_Y=ReadFromCharFrom7843();
  WriteCharTo7843(0xD0);      
  digitalWrite(DCLK,HIGH);
  digitalWrite(DCLK,LOW);
  TP_X=ReadFromCharFrom7843();
  digitalWrite(CS,HIGH);

 }

 void setup()
{
  unsigned char p;
  for(p=0;p<20;p++)
  {
    pinMode(p,OUTPUT);
  }
  pinMode(DOUT,INPUT);
  x0=1;
  y0=1;
  LCD_Init();  
  newpa();
  recan();
  digi(vh2);
  x3=x3+90;
  digi(vl2);
  spistar();  
}

void loop()
{  
  rx=0;
  ry=0;

  for(l3=0;l3<8;l3++)     //check touch coordinates 8 times to get a good average, skip counting if a zero value is found (prevents noise)
    {
        AD7843();
        lx=0;
        ly=-1*TP_Y;
        ly=4095+ly;                                             //4095= zero y-Signal
        if(ly > 0) lx=1*TP_X; else {lx=0;ly=0;rx=0;ry=0;l3=9; }
        rx=rx+lx;
        ry=ry+ly;
    }
  lx=(rx/8-180)/15;                                            //180= minimal x-value for touch-event
  ly=(ry/8-240)/11;                                            //240= minimal (> 4095) value for touch-event
  if(ly < 1) {lx=0;ly=0; }
  if(lx < 1) lx=0;

  if(ly > 309-k)
    {
        ly=0;
        if(lx > 200) k=k-2; else if (lx > 160) k=k+2;else
            if (lx > 100) vh2++; else if (lx > 40) vl2++; else newpa();
        lx=0;
        if (k<1) k=1;
        if (k>13) k=13;
        if (vh2>255) vh2=0;
        if (vl2>255) vl2=0;
        x3=65;
        digi(vh2);
        x3=x3+90;
        digi(vl2);
        recan();
    }

  if(ly > 299-k) ly=299-k;
  if(ly > 0)
    {
        x0=240-lx;
        if(x0 > 240-k) x0=240-k;
        y0=ly;
        l2=(k+1)*(k+1);
        digitalWrite(LCD_CS,LOW); 
        Address_set(x0,y0,x0+k,y0+k);
        for (l3=0; l3<l2; l3++) LCD_Write_DATA(vh2,vl2);
        digitalWrite(LCD_CS,HIGH); 
    }
  delay (50);
}

Share