Hello,
I have a problem, the code below lets a 4-wire resistive touch screen send midi cc. The problem is it constantly sends a message out when it isn't being touched.
Anyone have a fix to get it to idle while not in use?
Thanks!
// DS TouchScreen
/*
#define xLow 14
#define xHigh 15
#define yLow 16
#define yHigh 17
*/
#define xLow 17
#define xHigh 15
#define yLow 16
#define yHigh 14
#define midiChannel 1
int touchX, touchY;
void setup(){
// Setup serial / MIDI
Serial.begin(31250); // MIDI speed
// Serial.begin(9600); // Debug speed
}
void loop(){
touchScan();
touchOut();
delay(200);
}
void touchOut(){
sendCC(20, char(touchX)); // send CC message 10
sendCC(21, char(touchY)); // send CC message 11
}
// 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);
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);
}