touch scren as a switch?

hello again, now i am curious as to how i can go about making the touch screen i have hooked up to analog pins 0-3 also function as a switch.

The screen currently sends out midi CC data but i need to also have it send a midi note when i touch it anywhere and when i release my finger have the note shut off.

i tried a few things trying to modify code for a switch going in to a digital pin but couldn't get it to work. i am thinking there should be an easier way.

Posting the code would help us help you. But a simple addition to the code is all you really need. I haven’t worked with a touch screen before, so i don’t knwo what kind of input or form what pin or pins that input comes from. Assuming that if there is nothing touching the screen the pins read 0 then you can do a statement like this.

if(analogRead() > 0)
{
// play note
}
else
{ 
// play nothing
}

Or if its not zero but it sends out data in a certain range when touched you could do this.

if (analogRead() > lowvalue && analogRead() < high value)
{
// play note
}
else
{ 
// play nothing
}

Someone should be able to tell me how far off i am on this.

thanks digimike,
here is the code i am working with (this is the version without my mess of an attempt to add a switch).

// DS TouchScreen
/*
#define xLow  15
#define xHigh 17
#define yLow  16
#define yHigh 14
*/
//modified to match my sparkfun connector
#define xLow  15
#define xHigh 17
#define yLow  16
#define yHigh 14
#define midiChannel 1

 int touchX, touchY;
 int lastTouchX, lastTouchY;
 int pin1 = 1;

 
void setup(){
 //  Setup serial / MIDI
    Serial.begin(31250);       // MIDI speed
 //  Serial.begin(9600);    // Debug speed
}
 
void loop(){
 touchScan();
 touchOut(); 
   delay(200);
   




   
   
}

void touchOut()
{
   if(touchX > 0 && touchY > 0)
   {
        if(touchX > lastTouchX + 1 || touchX < lastTouchX - 1) //the 5 can be any whole number step
       {
         sendCC(20, char(touchX));  // send CC message 20
           lastTouchX = touchX;
       }

        if(touchY > lastTouchY + 1 || touchY < lastTouchY - 1)
        {
            sendCC(21, char(touchY));  // send CC message 21
           lastTouchY = touchY;
        }
   }
}



//  sends a CC message
void sendCC(char control, char data) {
  int cmd;
  cmd = 0xB0 | midiChannel;  // merge channel number
  Serial.print(cmd, BYTE);
  Serial.print((control & 0x7F), BYTE);
  Serial.print((data & 0x7F), BYTE);  // use the 0x7F to restrict the data to a maximum of 127
}

void touchScan(){
   pinMode(xLow,OUTPUT);
  pinMode(xHigh,OUTPUT);
  digitalWrite(xLow,LOW);
  digitalWrite(xHigh,HIGH);
 
  digitalWrite(yLow,LOW);
  digitalWrite(yHigh,LOW);
 
  pinMode(yLow,INPUT);
  pinMode(yHigh,INPUT);
  delay(10);
 
  //xLow has analog port -14 !!
  touchX=analogRead(yLow -14);
  
  touchX = map(touchX , 0, 1023, -15, 159); //set size from 0 to 127

 
  pinMode(yLow,OUTPUT);
  pinMode(yHigh,OUTPUT);
  digitalWrite(yLow,LOW);
  digitalWrite(yHigh,HIGH);
 
  digitalWrite(xLow,LOW);
  digitalWrite(xHigh,LOW);
 
  pinMode(xLow,INPUT);
  pinMode(xHigh,INPUT);
  delay(10);
 
  //xLow has analog port -14 !!
  touchY=analogRead(xLow - 14); 

  touchY = map(touchY , 0, 1023, -15, 162); //set size from 0 to 127
  
}

Ok so this is from a DS?

I did some searching and found this. http://mnicolato.altervista.org/arduino/ardtouch.htm

Looks like i could be helpful but you'll probably need to run it threw google translator first.

well i got it half working.
added some ghetto code that sends out another CC value along with the X value.
the problem is i need it to shut off when im not touching it anymore.

is there an easy way to tell the added CC value to be on and off? (0-127)

this is the section with the code i added (the CC22 value)

void touchOut()
{
   if(touchX > 0 && touchY > 0)
   {
        if(touchX > lastTouchX + 1 || touchX < lastTouchX - 1) //the 5 can be any whole number step
       {
         sendCC(20, char(touchX));  // send CC message 20
sendCC(22, char(touchX));  // send CC message 22
             lastTouchX = touchX;
       }

        if(touchY > lastTouchY + 1 || touchY < lastTouchY - 1)
        {
            sendCC(21, char(touchY));  // send CC message 21
           lastTouchY = touchY;
        }

is there an easy way to tell the added CC value to be on and off? (0-127)

Isn't that the second argument for the sendCC command?