MIDI Interface in progress
Dependencies: SPI_TFT_ILI9341 TFT_fonts Touch_tft PowerControl mbed USBMIDI
main.cpp
- Committer:
- Vekotin
- Date:
- 2014-02-06
- Revision:
- 14:31d5531114e0
- Parent:
- 2:478274cba6c3
File content as of revision 14:31d5531114e0:
#include "mbed.h" #include "SPI_TFT_ILI9341.h" #include "Arial12x12.h" #include "Arial28x28.h" #include "touch_tft.h" #include "USBMIDI.h" #include "touch_interface.h" // the TFT is connected to SPI pin 5-7 // the touch is connected to 19,20,16,17 touch_tft tft(p20,p19,p18,p17,p5, p6, p7, p14, p15, p21, "TFT"); // x+,x-,y+,y-,mosi, miso, sclk, cs, reset, dc USBMIDI midi; void buttons(int b, unsigned short color) { //button field if (b == 1) { tft.fillrect(3,88,78,158,color); } if (b == 2) { tft.fillrect(83,88,158,158,color); } if (b == 3) { tft.fillrect(163,88,238,158,color); } if (b == 4) { tft.fillrect(3,163,78,238,color); } if (b == 5) { tft.fillrect(83,163,158,238,color); } if (b == 6) { tft.fillrect(163,163,238,238,color); } if (b == 7) { tft.fillrect(3,243,78,318,color); } if (b == 8) { tft.fillrect(83,243,158,318,color); } if (b == 9) { tft.fillrect(163,243,238,318,color); } } void draw_buttons(unsigned short color) { unsigned int i = 1; for (i = 1; i<10; i++){ //draw buttons buttons(i, color); } } int ButtonState[9] = { 0,0,0, //A 1-3 0,0,0, //B 4-6 0,0,0, //C 7-9 }; void checkButtons(point p) { if (p.y > 88 && p.y < 158) { //ROW A if (p.x > 3 && p.x < 78) { //button 0 ButtonState[0]=1; } else { ButtonState[0]=0; } if (p.x > 83 && p.x < 158) { //button 1 ButtonState[1]=1; } else { ButtonState[1]=0; } if (p.x > 163 && p.x < 238) { //button 2 ButtonState[2]=1; } else { ButtonState[2]=0; } } if (p.y > 163 && p.y < 238) { //ROW B if (p.x > 3 && p.x < 78) { //button 3 ButtonState[3]=1; } else { ButtonState[3]=0; } if (p.x > 83 && p.x < 158) { //button 4 ButtonState[4]=1; } else { ButtonState[4]=0; } if (p.x > 163 && p.x < 238) { //button 5 ButtonState[5]=1; } else { ButtonState[5]=0; } } if (p.y > 243 && p.y < 318) { //ROW C if (p.x > 3 && p.x < 78) { //button 6 ButtonState[6]=1; } else { ButtonState[6]=0; } if (p.x > 83 && p.x < 158) { //button 7 ButtonState[7]=1; } else { ButtonState[7]=0; } if (p.x > 163 && p.x < 238) { //button 8 ButtonState[8]=1; } else { ButtonState[8]=0; } } } void light_pressed(unsigned short color){ for(int i=0;i<9;i++){ if(ButtonState[i]==1){ buttons(i, color); } } } int main(){ // PERUSPOHJA, ÄLÄ MUOKKAA! point p; unsigned short color = White; tft.claim(stdout); // send stdout to the TFT display tft.background(Black); // set background to black tft.foreground(White); // set chars to white tft.cls(); // clear the screen tft.set_font((unsigned char*) Arial12x12); // select the font tft.set_orientation(0); tft.calibrate(); tft.locate(170,0); //show coordinates printf(" x = "); tft.locate(170,12); printf(" y = "); tft.locate(0,0); printf(" MIDIMAN! "); tft.line(0,83,239,83,White); while (1) { color = White; draw_buttons(color); while (tft.is_touched(tft.get_touch())) { // touch p = tft.get_touch(); p = tft.to_pixel(p); // convert to pixel position checkButtons(p); light_pressed(Red); // light pressed button tft.locate(206,0); printf("%3d",p.x); tft.locate(206,12); printf("%3d",p.y); if (p.y > 88 && p.y < 158) { //ROW A if (p.x > 3 && p.x < 78) { //button 0 midi.write(MIDIMessage::NoteOn(48)); wait(0.25); midi.write(MIDIMessage::NoteOff(48)); wait(0.25); } } } } }