Auduino + synaptics touch panel

Hi everyone, i dont now if this is the right place for my post, im very sorry if its not, please move it ( sorry for my english too) i wasen't sure if this goes here or in interecative arte.

some days ago i found some laptop parts, the frames that old the keyboard, but witout the keyboard only the touchpads and some mini speakers ( pics soon ).

with a friend we manage to use a nintendo ds touch to control the auduino synth, i like to do the same with this touch module

i got working the synaptic touch panel in absolute mode with this code

#include <ps2.h>

PS2 mouse(6, 5);
unsigned int maxx,minx,maxy,miny;

void touch_init()
{
  mouse.write(0xff);  // reset
  mouse.read();  // ack byte
  mouse.read();  // blank */
  mouse.read();  // blank */
  mouse.write(0xf0);  // remote mode
  mouse.read();  // ack
  delayMicroseconds(100);
  mouse.write(0xe8);
  mouse.read();  // ack byte
  mouse.write(0x03); // x1  ( x1 * 64  +  x2 * 16  +  x3 * 4  +  x4   == modebyte )
  mouse.read();  // ack byte
  mouse.write(0xe8);
  mouse.read();  // ack byte
  mouse.write(0x00); // x2
  mouse.read();  // ack byte
  mouse.write(0xe8);
  mouse.read();  // ack byte
  mouse.write(0x00); // x3
  mouse.read();  // ack byte
  mouse.write(0xe8);
  mouse.read();  // ack byte
  mouse.write(0x01); // x4
  mouse.read();  // ack byte
  mouse.write(0xf3); // set samplerate 20 (stores mode) 
  mouse.read();  // ack byte
  mouse.write(0x14);
  mouse.read();  // ack byte
  delayMicroseconds(100); 
}

void setup()
{
  Serial.begin(9600);
  touch_init();
  maxx = 5850;
  minx = 1250;
  maxy = 4850;
  miny = 1000;
}

void loop()
{
  byte mstat1;
  byte mstat2;
  byte mxy;
  byte mx;
  byte my;
  byte mz;

  int realx;
  int realy;

  unsigned int cx,cy;

  mouse.write(0xeb);
  mouse.read();
  
  mstat1 = mouse.read();
  mxy = mouse.read();
  mz = mouse.read();
  mstat2 = mouse.read();
  mx = mouse.read();
  my = mouse.read();

  // collect the bits for x and y
  cx = (((mstat2 & 0x10) << 8) | ((mxy & 0x0F) << 8) | mx );
  cy = (((mstat2 & 0x20) << 7) | ((mxy & 0xF0) << 4) | my );
  
  // determine real values
  realx = map(cx,minx,maxx,0,1024);
  realy = map(cy,miny,maxy,0,1024);
    
  if(realx<0)realx=0;
  if(realx>1024)realx=1024;
  if(realy<0)realy=0;
  if(realy>1024)realy=1024;

   
  Serial.print(mstat1, BIN);
  Serial.print("\tX=");
  Serial.print(realx, DEC);
  Serial.print("\tY=");
  Serial.print(realy, DEC);
  Serial.println();
  
  
   
  delay(20);
}

this gives me an output from 0 to 1024 in X / Y

then i merged it with the auduino code like this

" see code.txt attach "

when the touch loop is off the synth works, but when is on it dosen't

if i comment // a line in the part where the loop gets the bytes like this

mouse.write(0xeb);
mouse.read();
mstat1 = mouse.read();
mxy = mouse.read();
// mz = mouse.read();
mstat2 = mouse.read();
mx = mouse.read();
my = mouse.read();

the synth works but obviously the touch dont

everything is well connected the touch works great alone, i realy would thank if anyone can help me

bye

code.txt (7.99 KB)