Hi.
I'm using arduino mega2560 for a project that measures some values then prints it on a serial uart LCD.
I want to use the touchscreen of LCD, So i receive a string from serial port No.3 like this: [TP:83,125] that 83 is X of touch point and 125 is Y point.
I'm using the code below:
if(Serial3.available()) {
bargasht=Serial3.readString();
view[0]=bargasht[4];
view[1]=bargasht[5];
view[2]=bargasht[6];
view[3]=bargasht[7];
view[4]=bargasht[8];
view[5]=bargasht[9];
view[6]=bargasht[10];
converttouchpoint();
}
then:
void converttouchpoint(){
i=0;
switch(view[i]){
case '0':
xtouch[0]=0;
xflag=1;
break;
case '1':
xtouch[0]=1;
xflag=1;
break;
case '2':
xflag=1;
xtouch[0]=2;
break;
case '3':
xtouch[0]=3;
xflag=1;
break;
case '4':
xtouch[0]=4;
xflag=1;
break;
case '5':
xtouch[0]=5;
xflag=1;
break;
case '6':
xtouch[0]=6;
xflag=1;
break;
case '7':
xtouch[0]=7;
xflag=1;
break;
case '8':
xtouch[0]=8;
xflag=1;
break;
case '9':
xtouch[0]=9;
xflag=1;
break;
default:
xtouch[0]=0;break;}
i++;
switch(view[i]){
case',':
goto ygettouch;
break;
case '0':
xtouch[1]=0;
break;
case '1':
xtouch[1]=1;
break;
case '2':
xtouch[1]=2;
break;
case '3':
xtouch[1]=3;
break;
case '4':
xtouch[1]=4;
break;
case '5':
xtouch[1]=5;
break;
case '6':
xtouch[1]=6;
break;
case '7':
xtouch[1]=7;
break;
case '8':
xtouch[1]=8;
break;
case '9':
xtouch[1]=9;
break;
default:
xtouch[1]=0;break;}
i++;
switch(view[i]){
case',':
goto ygettouch;
case '0':
xtouch[2]=0;
i++;
break;
case '1':
xtouch[2]=1;
i++;
break;
case '2':
xtouch[2]=2;
i++;
break;
case '3':
xtouch[2]=3;
i++;
break;
case '4':
xtouch[2]=4;
i++;
break;
case '5':
xtouch[2]=5;
i++;
break;
case '6':
xtouch[2]=6;
i++;
break;
case '7':
xtouch[2]=7;
i++;
break;
case '8':
xtouch[2]=8;
i++;
break;
case '9':
xtouch[2]=9;
i++;
break;
default:
xtouch[2]=0;break;}
ygettouch:
if(i==1){xtouc=xtouch[0];j=i;}
if(i==2){xtouc=(xtouch[0]*10)+xtouch[1];j=i;}
if(i==3){xtouc=(xtouch[0]*100)+(xtouch[1]*10)+(xtouch[2]);j=i;}
i++;
switch(view[i]){
case '0':
ytouch[0]=0;break;
case '1':
ytouch[0]=1;break;
case '2':
ytouch[0]=2;break;
case '3':
ytouch[0]=3;break;
case '4':
ytouch[0]=4;break;
case '5':
ytouch[0]=5;break;
case '6':
ytouch[0]=6;break;
case '7':
ytouch[0]=7;break;
case '8':
ytouch[0]=8;break;
case '9':
ytouch[0]=9;break;
default:
ytouch[0]=0;break;}
i++;
switch(view[i]){
case']':
goto endofgettouch;
case '0':
ytouch[1]=0;break;
case '1':
ytouch[1]=1;break;
case '2':
ytouch[1]=2;break;
case '3':
ytouch[1]=3;break;
case '4':
ytouch[1]=4;break;
case '5':
ytouch[1]=5;break;
case '6':
ytouch[1]=6;break;
case '7':
ytouch[1]=7;break;
case '8':
ytouch[1]=8;break;
case '9':
ytouch[1]=9;break;
default:
ytouch[1]=0;break;}
i++;
switch(view[i]){
case']':
goto endofgettouch;break;
case '0':
ytouch[2]=0;break;
case '1':
ytouch[2]=1;break;
case '2':
ytouch[2]=2;break;
case '3':
ytouch[2]=3;break;
case '4':
ytouch[2]=4;break;
case '5':
ytouch[2]=5;break;
case '6':
ytouch[2]=6;break;
case '7':
ytouch[2]=7;break;
case '8':
ytouch[2]=8;break;
case '9':
ytouch[2]=9;break;
default:
ytouch[2]=0;break;}
i++;
endofgettouch:
if((i-j)==2){ytouc=ytouch[0];}
if((i-j)==3){ytouc=(ytouch[0]*10)+ytouch[1];}
if((i-j)==4){ytouc=(ytouch[0]*100)+(ytouch[1]*10)+ytouch[2];}
}
it works right but not well because the values are correct always but it takes a long time to read the position of touch point about 800ms!!
would you plz help me to find a better solution?
thanks a lot.