here's my code:
Code: Select all
usart_putc(0x05);
usart_putc(0x01);
wait(); //activates touchscreen
while(1){
if(!uart_buffer_empty()){ //recieved touchscreen input
_delay_ms(100.0);
input_decode();
}
}
//decodes the input x,y from the LCD
void input_decode(){
unsigned char tempin[10];
unsigned char xin[10];
unsigned char yin[10];
unsigned char temp;
int i = 0;
int x, y, tmp;
while(!uart_buffer_empty()){
temp = usart_getc(); //read the buffer
if(temp == ','){
break;
}
else{
tempin[i++] = temp;
}
}
tmp = i;
for(int k = 0; k <= tmp; k++){
xin[k] = tempin[i--]; //reverses the character order
}
i = 0;
while(!uart_buffer_empty()){
temp = usart_getc(); //read the buffer
if(temp == ' '){
break;
}
else{
tempin[i++] = temp;
}
}
tmp = i;
for(int k = 0; k <= tmp; k++){
yin[k] = tempin[i--]; //reverses the character order
}
//code continues to atoi the char arrays and use them as coordinates
I know in the documentation its only supposed to respond with 4 bytes:
"X,Y "
'X' = byte value of x coord
',' = a char comma
'Y' = byte value of y coord
' ' = stop character....
What am I doing wrong here at I'm receiving so many bytes? Are they being sent in characters (what I assumed when the int values weren't reading in properly)
Please help!