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);
}