Digital Touch Pad for Guitar tutorial

hello All,

A few years back I created a touch pad for my guitar which output midi signal to manipulate an audio processing unit, (kaoss pad KP2). if you would like to see mine in action follow the following link to my youtube channel: Guitar Digital Touchscreen - YouTube.

Without this forum I could have never finished the project, so as a token of gratitude and also help for any other person trying to do the same thing; here is my code and a schematic(ish) diagram: http://postimg.org/image/ons2fdtqb/, I hope it helps:

// Touch panel output wiring. These define the pins 
// used to apply voltages across the touch screen
#define topOutput 5     // TOP to Digital output dig5 
#define leftOutput 6    // LEFT to digital output dig6
#define bottomOutput 7  // BOTTOM to digital output dig7
#define rightOutput 8   // RIGHT to digital output dig8
// Touch panel input wiring. These define the analog 
// input pins used to read the voltage from the screen
#define topInput 0      // TOP also to analog input an0 
#define rightInput 1    // RIGHT also to analog input an3 
//blinkM
#include "Wire.h"
#include "BlinkM_funcs.h"
#include "EEPROM.h"
#define blinkm_addr 0x09
	int startup=1;
//int which determines whether its whammy pedal code or kaoss pad code
	int pedaleeprom;
	int pedal = EEPROM.read(pedaleeprom); //KP2 = 0 (flashes white)  KP3 = 1(flashes yellow) whammy = 2(flashes red)
	const int pedalselectPin = 9;
	int pedalState = 0;
	int lastpedalState = 0;
//KP2 ints
	int holdkp2 = 0;
	int Holdtch = 0;
//KP3 ints
	int holdkp3 = 0;
//hold button ints
	const int buttonPin = 3;
	int Hld = 0;
	int buttonState = 0;
	int lastButtonState = 0;
//encoder ints
	int val; 
	int encoder0PinA = 2;
	int encoder0PinB = 4;
	int encoder0Poseeprom;
	int encoder0Pos = EEPROM.read(encoder0Poseeprom);
	int encoder0PinALast = LOW;
	int n = LOW;
	int currentenc = 200;
	int cenc=0;
	int encoderrunning =0;
//touch pad ints
	int Tch = 0;
	int touchX = 0; 
	int touchY = 0; 
	int ledPin = 13;
	int midiX = 0;
	int midiY = 0;
//blinkM ints
	int LedX = 0;
	int LedY = 0;
	int Led = 0;
	int blinkX = 300;
	int blinkY = 300;
	int effecteeprom;
	int effect=EEPROM.read(effecteeprom);
	int del_time=8;
	const int lightselectPin = 10;
	int lightState = 0;
	int lastlightState = 0;
	byte hue_val;
	
void setup(){ 
	pinMode(encoder0PinA, INPUT); 
	pinMode(encoder0PinB, INPUT); 
	pinMode(buttonPin, INPUT); 
	pinMode(pedalselectPin, INPUT);
	pinMode(lightselectPin, INPUT);
	attachInterrupt(0, doEncoder, CHANGE);  // encoder pin on interrupt 0 - pin 2
	Serial.begin(31250);//31250  9600
	Serial.flush();
	//blinkM
	BlinkM_beginWithPower();
	BlinkM_stopScript(blinkm_addr);  // turn off startup script               
} 

void doEncoder(){//encoder loop
	if (EEPROM.read(encoder0Poseeprom)==255){
		encoder0Pos=0}
	else {
		encoder0Pos=EEPROM.read(encoder0Poseeprom)
	}
	if (EEPROM.read(pedaleeprom)==255){
		pedal=0}
	else {
		pedal=EEPROM.read(pedaleeprom)
	}
	n = digitalRead(encoder0PinA);
	if ((encoder0PinALast == LOW) && (n == HIGH)) {
		if (digitalRead(encoder0PinB) == LOW) {
			encoder0Pos++;
		} 
		else {
			encoder0Pos--;
		}
	} 
	encoder0PinALast = n;
	if (pedal == 0){//KP2
		if (encoder0Pos<0){(encoder0Pos=99);
		}
		else if (encoder0Pos>99){(encoder0Pos=0);
		}
	}
	else if (pedal == 1){//KP3
		if (encoder0Pos<0){
			(encoder0Pos=127);
		}
		else if (encoder0Pos>127){
			(encoder0Pos=0);
		}
	}
	else if (pedal == 2){//whammy
		if (encoder0Pos<17){
			(encoder0Pos=34);
		}
		else if (encoder0Pos>34){
			(encoder0Pos=17);
		}
	}
	if (currentenc != encoder0Pos){
		encoderrunning=1;
		if (pedal !=2){
			holdkp2=0;
			holdkp3=0;
		}
		midiCC(0xC0, 0, encoder0Pos);
		//Serial.print("encoder possition=");
		//Serial.println(encoder0Pos);
		EEPROM.write(encoder0Poseeprom, encoder0Pos);
		currentenc=encoder0Pos;
		encoderrunning=0;
	}
}

//main loop
void loop() {
	if (EEPROM.read(effecteeprom)==255){
		effect=10}
	else {
		effect=EEPROM.read(effecteeprom)
	}
	//background select
	lightState = digitalRead(lightselectPin);
	buttonState = digitalRead(buttonPin);
	if ((lightState != lastlightState) or (buttonState == HIGH)){
		if  ((lightState == HIGH) and (buttonState != HIGH) and (effect<18)){
			effect++;
		}	
		else if  ((lightState== HIGH) and (buttonState != HIGH) and (effect>17)){
			effect=0;
		}
		if  ((lightState == HIGH) and (buttonState != HIGH)){
			hue_val =(150);
			Wire.beginTransmission(0x09); //goes off
			Wire.send('f');
			Wire.send(0xff);
			Wire.send('h');
			Wire.send(hue_val);
			Wire.send(0xff);
			Wire.send(0x00);
			Wire.endTransmission();
				delay(50);
			Wire.beginTransmission(0x09);//flashes blue
			Wire.send('f');
			Wire.send(0xff);
			Wire.send('h');
			Wire.send(hue_val);
			Wire.send(0xff);
			Wire.send(0xff);
			Wire.endTransmission();
				delay(50);
			Wire.beginTransmission(0x09); //goes off
			Wire.send('f');
			Wire.send(0xff);
			Wire.send('h');
			Wire.send(hue_val);
			Wire.send(0xff);
			Wire.send(0x00);
			Wire.endTransmission();
				delay(900);
				Led=0;
			//Serial.println("LED Effect=");
			//Serial.println(effect);
		}
		if((lightState== HIGH) and (buttonState == HIGH)){
			effect=9;
			hue_val =(150);
			Wire.beginTransmission(0x09); //goes off
			Wire.send('f');
			Wire.send(0xff);
			Wire.send('h');
			Wire.send(hue_val);
			Wire.send(0xff);
			Wire.send(0x00);
			Wire.endTransmission();
				delay(50);
			Wire.beginTransmission(0x09);  //flashes blue
			Wire.send('f');
			Wire.send(0xff);
			Wire.send('h');
			Wire.send(hue_val);
			Wire.send(0xff);
			Wire.send(0xff);
			Wire.endTransmission();	
				Led=0;
			//Serial.println("LED Effect=");
			//Serial.println(effect);
		}
	EEPROM.write(effecteeprom, effect);
	}
	lastlightState = lightState;	
	//pedal select
	pedalState = digitalRead(pedalselectPin);
		if (pedalState != lastpedalState) {
			if  (pedalState == HIGH and pedal < 2){
				pedal++;
			}
			else if (pedalState == HIGH and pedal==2){
			    pedal=0;
			}
			if	( pedal==0){//KP2
				hue_val =(128); 
			}
			else if  (pedal==1){//KP3
				hue_val =(40);
			}
			else if  (pedal==2){ 
				hue_val =(255);
			}				
			if	(pedalState == HIGH){
				Wire.beginTransmission(0x09); //goes off
				Wire.send('f');
				Wire.send(0xff);
				Wire.send('h');
				Wire.send(hue_val);
				Wire.send(0xff);
				Wire.send(0x00);
				Wire.endTransmission();
					delay(50);
				Wire.beginTransmission(0x09);//flashes blue
				Wire.send('f');
				Wire.send(0xff);
				Wire.send('h');
				Wire.send(hue_val);
				Wire.send(0xff);
				Wire.send(0xff);
				Wire.endTransmission();
					delay(50);
				Wire.beginTransmission(0x09); //goes off
				Wire.send('f');
				Wire.send(0xff);
				Wire.send('h');
				Wire.send(hue_val);
				Wire.send(0xff);
				Wire.send(0x00);
				Wire.endTransmission();
					delay(900);
					Led=0;
				//Serial.print("device=");
				//Serial.println(pedal);
				delay(250);
			}
		EEPROM.write(pedaleeprom, pedal);
		}
	lastpedalState=pedalState;
	//touch function of pad
	if (touched() and (encoderrunning==0)){
		if (Tch==0){
			midiCC(0xB0,92,127);
			//Serial.println("touch on");
			Tch=1;
		}
		midiX = map(touchX,250,800,1,126);  // maps the value range of the axis to midi 0->127
		midiY = map(touchY,200,800,0,126);  // maps the value range of the axis to midi 0->127
		if (touchX > 800){
				midiX = 127;
			}
			else if (touchX < 250){
				midiX = 0;
			}
			if (touchY > 800){
				midiY = 127;
			}
			else if (touchY < 200){
				midiY = 0;
			}
		if (pedal != 2){//KP void
			midiCC(0xB0, 13, midiX);    
			//Serial.print("X=  "); // sends midi control change for touch pad X axis
			//Serial.print(midiX); 
			midiCC(0xB0, 12, midiY);
			//Serial.print(" Y=  ");   // sends midi control change for touch pad y axis	
			//Serial.println(midiY);
			if (cenc != encoder0Pos){
				midiCC(0xB0,92,127);
				//Serial.println("touch on");
				cenc=encoder0Pos;
			}
		}
		else if (pedal == 2){//whammy void
			midiCC(0xB0, 11, midiY);
			//Serial.print(" Y=  ");
			//Serial.println(midiY);
		}
		//blinkm
		LedY = map(touchY,180,820,0,255);    // read the hue pot
		LedX = map(touchX,230,840,0,255);    // read the hue pot
		hue_val =((LedX+LedY)/2);    // read the hue pot
		Wire.beginTransmission(0x09);
	
}

second part of the code

	Wire.send('f');
		Wire.send(0xff);
		Wire.send('h');
		Wire.send(hue_val);
		Wire.send(0xff);
		Wire.send(0xff);
		Wire.endTransmission();	
		Led=0;
		Holdtch=1;
	}
	else {
		if (Tch==1 and holdkp2==0){
			midiCC(0xB0,92,0);
			//Serial.println("touch off");
			Tch=0;
		}
		if (Led==0){
			Wire.beginTransmission(0x09);
			Wire.send('f');
			Wire.send(del_time);
			Wire.send('p');
			Wire.send(effect);
			Wire.send(0x00);
			Wire.send(0x00);
			Wire.endTransmission();
			//Serial.println("screen not touched LED effect");
			    Led=1;
		}
		Holdtch=0;
	}
	//hold functions
	if (buttonState != lastButtonState) {
		if (pedal==0){//hold function for KP2
			if  (buttonState == HIGH and lightState != HIGH and holdkp2==0){
				if (Tch==0){
					midiCC(0xB0, 92, 127);
					//Serial.println("KP2 hold on");
					Tch=1;
				}
				holdkp2=1;
			}
			else if  (buttonState == HIGH and lightState != HIGH and holdkp2==1){
				if (Holdtch==0){
					midiCC(0xB0, 92, 0);
					//Serial.println("KP2 hold off");
				}
				holdkp2=0;			
			}
		}
		if (pedal==1){//hold function for KP3
			if  (buttonState == HIGH and lightState != HIGH and holdkp3==0){
				midiCC(0xB0, 95, 127);
				//Serial.println("KP3 hold on");
				holdkp3=1;
			}
			else if  (buttonState == HIGH and lightState != HIGH and holdkp3==1){
				midiCC(0xB0, 95, 0);
				//Serial.println("KP3 hold off");
				holdkp3=0;
			}
		}
		if (pedal==2){//hold function for Whammy
			if  ((buttonState == HIGH) and Hld==0){
				midiCC(0xB0, 0, 127);
				//Serial.println("Whammy hold on");
				Hld=1;
			}
			else if  ((buttonState == HIGH) and Hld==1){
				midiCC(0xB0, 0, 0);
				//Serial.println("Whammy hold off");
				Hld=0;
			}
		}
	}
	lastButtonState=buttonState;
	//permanent storage of variables
	
}

// return TRUE if touched, and coords in touchX and touchY
boolean touched(){
	boolean touch = false;
	pinMode(leftOutput, OUTPUT); 
	digitalWrite(leftOutput, LOW);     // set Left = ground 
	pinMode(rightOutput, OUTPUT); 
	digitalWrite(rightOutput, HIGH);   // set Right = Vcc 
	pinMode(topOutput, INPUT);         // Sets Top and Bottom to inputs
	pinMode(bottomOutput, INPUT);      // to give them high impedence 
	delay(10);
	touchY = analogRead(topInput) ;   // wait a bit, then read from Top 
	pinMode(bottomOutput, OUTPUT); 
	digitalWrite(bottomOutput, LOW); // Set Bottom to 0v
	pinMode(topOutput, OUTPUT); 
	digitalWrite(topOutput, HIGH);  // set Top to +Vcc
	pinMode(rightOutput, INPUT); 
	pinMode(leftOutput, INPUT); 
	delay(10);
	touchX = analogRead(rightInput) ; // wait a bit, then read from Right
	 
	if(touchX < 1000 and touchY < 1000)
	touch = true; 
	return touch; 
}

void midiCC(char command, char value1, char value2){
	Serial.print(command, BYTE);
	Serial.print(value1, BYTE);
	Serial.print(value2, BYTE);

Hello Chris, I just saw one of your videos showcasing this project and wanted try building it. But I'm getting an error regarding BlinkM_funcs.h when compiling. Do you happen to know where I can find a .zip of that library? I have not been able to find a version that will install correctly.

Below is the exact error I'm getting. When I've gotten this type of message in the past, it's always been due to not having the library installed or having the wrong library installed. I know this is a very old post, but I hope you're still around and feel like helping - Thanks!

13:26: fatal error: BlinkM_funcs.h: No such file or directory
 #include "BlinkM_funcs.h"
                          ^
compilation terminated.
Using library Wire at version 1.0 in folder: /Users/James/Library/Arduino15/packages/arduino/hardware/avr/1.6.19/libraries/Wire 
exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.