Silvius
Published © CC BY

XY MIDI Pad With Arduino and TFT

Build a XY MIDI PAD using Arduino Mega and a TFT touchscreen display/shield. (project imported)

BeginnerFull instructions provided1 hour10,392
XY MIDI Pad With Arduino and TFT

Things used in this project

Hardware components

Arduino Mega
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

UTFT.zip

UTFT.zip

UTOUCH.zip

UTOUCH.zip

UTouchWorking.zip

UTouchWorking.zip

SimplerCalibration.zip

SimplerCalibration.zip

MIDIPad.zip

MIDIPad.zip

Code

Code snippet #4

Plain text
void UTouch::InitTouch(byte orientation){
    orient                	= orientation;
    _default_orientation        = 0;
    touch_x_left            	= 306;     //enter number for left most touch
    touch_x_right           	= 3966;    //enter number for right most touch
    touch_y_bottom            	= 3906;    //enter number for bottom most touch
    touch_y_top            	= 174;     //enter number for top most touch
    disp_x_size            	= 320;     // do not forget them if different
    disp_y_size            	= 240;     // do not forget them if different
    prec                	= 10;
// ..................................................

Code snippet #6

Plain text
void draw_Pad(long x, long y)<br>{
      // we draw 3 three lines for x and three lines for y
      // for better visibility
      myGLCD.setColor(pad_bk);
      myGLCD.drawLine(old_x-1,pad_topY,old_x-1,pad_bottomY); // clear old line x-1
      myGLCD.drawLine(old_x+1,pad_topY,old_x+1,pad_bottomY); // clear old line x+1
      myGLCD.drawLine(old_x,pad_topY,old_x,pad_bottomY);     // clear old line x
      myGLCD.drawLine(pad_topX,old_y-1,pad_bottomY,old_y-1); // clear old line y-1    
      myGLCD.drawLine(pad_topX,old_y+1,pad_bottomY,old_y+1); // clear old line y+1    
      myGLCD.drawLine(pad_topX,old_y,pad_bottomY,old_y);     // clear old line y
      myGLCD.setColor(reticle_color);
      myGLCD.drawLine(x-1,pad_topY,x-1,pad_bottomY);         // draw new line x-1
      myGLCD.drawLine(x+1,pad_topY,x+1,pad_bottomY);         // draw new line x+1
      myGLCD.drawLine(x,pad_topY,x,pad_bottomY);             // draw new line x
      myGLCD.drawLine(pad_topX,y-1,pad_bottomX,y-1);         // draw new line1 y-1
      myGLCD.drawLine(pad_topX,y+1,pad_bottomX,y+1);         // draw new line2 y+1
      myGLCD.drawLine(pad_topX,y,pad_bottomX,y);             // draw new line3 y
}

Code snippet #7

Plain text
void SendMIDIControl(byte channel, byte controller, byte value) {
byte tmpChannel = (channel & 0b00001111)-1; //0= channel1...1=channel2... etc
  tmpChannel = 0b10110000 + tmpChannel;     //midi data first bit allways 1, 
					    //+ 011 control change command 
					    //+ midi channel
  byte tmpController = controller & 0b01111111;    //midi data first bit allways 0
  byte tmpValue = value & 0b01111111;              //midi data first bit allways 0
  Serial1.write(tmpChannel);
  Serial1.write(tmpController);
  Serial1.write(tmpValue);
}

Code snippet #8

Plain text
byte CoordToMIDI(unsigned int coord){
  float temp;
  temp=coord;
  temp=temp/1.72;
  return (byte)temp;  
}

Code snippet #9

Plain text
byte CoordXToMIDI(unsigned int coord){
  float temp;
  temp=coord;
  temp=temp/another_value1; // depend of your virtual pad x size
  return (byte)temp;  
}

byte CoordYToMIDI(unsigned int coord){
  float temp;
  temp=coord;
  temp=temp/another_value2; // depend of your virtual pad y size
  return (byte)temp;  
}

Credits

Silvius
1 project • 4 followers

Comments