MIDI Interface in progress
Dependencies: SPI_TFT_ILI9341 TFT_fonts Touch_tft PowerControl mbed USBMIDI
Diff: main.cpp
- Revision:
- 14:31d5531114e0
- Parent:
- 2:478274cba6c3
--- a/main.cpp Mon Jan 20 11:20:51 2014 +0000 +++ b/main.cpp Thu Feb 06 13:57:03 2014 +0000 @@ -4,13 +4,14 @@ #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 @@ -56,47 +57,80 @@ } -void light_pressed(unsigned short color, point p) +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 1 - buttons(1, color); + if (p.x > 3 && p.x < 78) { //button 0 + ButtonState[0]=1; + } else { + ButtonState[0]=0; } - if (p.x > 83 && p.x < 158) { //button 2 - buttons(2, color); + if (p.x > 83 && p.x < 158) { //button 1 + ButtonState[1]=1; + } else { + ButtonState[1]=0; } - if (p.x > 163 && p.x < 238) { //button 3 - buttons(3, color); + 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 4 - buttons(4, color); + if (p.x > 3 && p.x < 78) { //button 3 + ButtonState[3]=1; + } else { + ButtonState[3]=0; } - if (p.x > 83 && p.x < 158) { //button 5 - buttons(5, color); + if (p.x > 83 && p.x < 158) { //button 4 + ButtonState[4]=1; + } else { + ButtonState[4]=0; } - if (p.x > 163 && p.x < 238) { //button 6 - buttons(6, color); + 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 7 - buttons(7, color); + if (p.x > 3 && p.x < 78) { //button 6 + ButtonState[6]=1; + } else { + ButtonState[6]=0; } - if (p.x > 83 && p.x < 158) { //button 8 - buttons(8, color); + if (p.x > 83 && p.x < 158) { //button 7 + ButtonState[7]=1; + } else { + ButtonState[7]=0; } - if (p.x > 163 && p.x < 238) { //button 9 - buttons(9, color); + if (p.x > 163 && p.x < 238) { //button 8 + ButtonState[8]=1; + } else { + ButtonState[8]=0; } } } -int main() { +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! @@ -113,9 +147,9 @@ tft.calibrate(); - tft.locate(180,0); //show coordinates + tft.locate(170,0); //show coordinates printf(" x = "); - tft.locate(180,12); + tft.locate(170,12); printf(" y = "); tft.locate(0,0); @@ -131,12 +165,22 @@ p = tft.get_touch(); p = tft.to_pixel(p); // convert to pixel position - light_pressed(Red,p); // light pressed button + checkButtons(p); + light_pressed(Red); // light pressed button - tft.locate(216,0); + tft.locate(206,0); printf("%3d",p.x); - tft.locate(216,12); - printf("%3d",p.y); + 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); + } + } } } @@ -146,4 +190,3 @@ -