MIDI Interface in progress
Dependencies: SPI_TFT_ILI9341 TFT_fonts Touch_tft PowerControl mbed USBMIDI
Revision 4:76c054f8b97e, committed 2014-02-06
- Comitter:
- MetropoliaMies
- Date:
- Thu Feb 06 06:41:30 2014 +0000
- Parent:
- 3:c8a476a218e3
- Child:
- 5:8e13103b41be
- Commit message:
- teeeeesti;
Changed in this revision
light_pressed.h | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/light_pressed.h Thu Feb 06 06:41:30 2014 +0000 @@ -0,0 +1,169 @@ +#include "touch_tft.h" +#include "SPI_TFT_ILI9341.h" + + +int slider; +int shift = 0; + +touch_tft tft(p20,p19,p18,p17,p5, p6, p7, p14, p15, p21, "TFT"); // x+,x-,y+,y-,mosi, miso, sclk, cs, reset, dc + + +void buttons(int b, unsigned short color) //button field +{ + + if (b == 0) { // Shift Button + tft.fillrect(3,20,63,80, color); + } + + + if (b == 1 && shift == 1) { // Piirra liukunappain jos shift paalla + tft.fillrect(3,88,78,318,color); + } else + tft.fillrect(3,88,78,158,color); + if (shift == 0) { + if (b == 2) { + tft.fillrect(83,88,158,158,color); + } + if (b == 3) { + tft.fillrect(163,88,238,158,color); + } + } + + if (b == 4 && shift == 0) { // Jos shift painettan, ei piirra mitaan + 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 && shift == 0) { // Jos shift painettan, ei piirra mitaan + 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 light_pressed2(unsigned short color2, point p) +{ + if (p.y >20 && p.y < 80) { // Shift Button + if (p.x > 3 && p.x < 63) { + buttons(0, color2); + shift = 0; + } + } + + if (p.x > 3 && p.x < 78) { //Slider + if (p.y > 88 && p.y < 111) { //button 1 + slider = 100; + } + if (p.y > 111 && p.y < 134) { //button 2 + slider = 90; + } + if (p.y > 134 && p.y < 157) { //button 3 + slider = 80; + } + if (p.y > 157 && p.y < 180) { //button 3 + slider = 70; + } + if (p.y > 180 && p.y < 203) { //button 3 + slider = 60; + } + if (p.y > 203&& p.y < 226) { //button 3 + slider = 50; + } + if (p.y > 226 && p.y < 249) { //button 3 + slider = 40; + } + if (p.y > 249 && p.y < 272) { //button 3 + slider = 30; + } + if (p.y > 272 && p.y < 295) { //button 3 + slider = 20; + } + if (p.y > 295 && p.y < 318) { //button 3 + slider = 10; + } + } + if (p.y > 163 && p.y < 238) { //ROW B + if (p.x > 83 && p.x < 158) { //button 5 + buttons(5, color2); + + } + if (p.x > 163 && p.x < 238) { //button 6 + buttons(6, color2); + + } + } + + if (p.y > 243 && p.y < 318) { //ROW C + if (p.x > 83 && p.x < 158) { //button 8 + buttons(8, color2); + } + if (p.x > 163 && p.x < 238) { //button 9 + buttons(9, color2); + + } + } +} + + +void light_pressed(unsigned short color, point p) +{ + if (p.y >20 && p.y < 80) { // Shift Button + if (p.x > 3 && p.x < 63) { + buttons(0, color); + shift = 1; + } + } + + if (p.y > 88 && p.y < 158) { //ROW A + if (p.x > 3 && p.x < 78) { //button 1 + buttons(1, color); + } + if (p.x > 83 && p.x < 158) { //button 2 + buttons(2, color); + } + if (p.x > 163 && p.x < 238) { //button 3 + buttons(3, color); + + } + } + + if (p.y > 163 && p.y < 238) { //ROW B + if (p.x > 3 && p.x < 78) { //button 4 + buttons(4, color); + + } + if (p.x > 83 && p.x < 158) { //button 5 + buttons(5, color); + + } + if (p.x > 163 && p.x < 238) { //button 6 + buttons(6, color); + + } + } + + if (p.y > 243 && p.y < 318) { //ROW C + if (p.x > 3 && p.x < 78) { //button 7 + buttons(7, color); + } + if (p.x > 83 && p.x < 158) { //button 8 + buttons(8, color); + } + if (p.x > 163 && p.x < 238) { //button 9 + buttons(9, color); + + } + } +} + + +
--- a/main.cpp Thu Jan 30 06:30:10 2014 +0000 +++ b/main.cpp Thu Feb 06 06:41:30 2014 +0000 @@ -1,179 +1,103 @@ #include "mbed.h" -#include "SPI_TFT_ILI9341.h" + #include "Arial12x12.h" #include "Arial28x28.h" -#include "touch_tft.h" + #include "USBMIDI.h" +#include "light_pressed.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 -PwmOut led1(LED1); -PwmOut led2(LED2); -PwmOut led3(LED3); -PwmOut led4(LED4); -int q,w,e,r,s; - -float brightness = 0.0; -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); - } - -} +Serial pc(USBTX, USBRX); + +void draw_buttons(unsigned short color) +{ -void draw_buttons(unsigned short color) { - - unsigned int i = 1; - - for (i = 1; i<10; i++){ //draw buttons - buttons(i, color); - } - -} - -void light_pressed(unsigned short color, 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 > 83 && p.x < 158) { //button 2 - buttons(2, color); - } - if (p.x > 163 && p.x < 238) { //button 3 - buttons(3, color); - brightness += 0.01; - } - } + unsigned int i = 0; - if (p.y > 163 && p.y < 238) { //ROW B - if (p.x > 3 && p.x < 78) { //button 4 - buttons(4, color); - s = 1; - } - if (p.x > 83 && p.x < 158) { //button 5 - buttons(5, color); - led1 = 0.5; - } - if (p.x > 163 && p.x < 238) { //button 6 - buttons(6, color); - s = 2; - } - } + for (i = 0; i<10; i++) { //draw buttons + buttons(i, color); + tft.locate(10,50); + printf("Shift"); - if (p.y > 243 && p.y < 318) { //ROW C - if (p.x > 3 && p.x < 78) { //button 7 - buttons(7, color); - } - if (p.x > 83 && p.x < 158) { //button 8 - buttons(8, color); - } - if (p.x > 163 && p.x < 238) { //button 9 - buttons(9, color); - brightness -= 0.01; - } } } -int main() { - +int main() +{ + // PERUSPOHJA, ÄLÄ MUOKKAA! - + point p; unsigned short color = White; + unsigned short color2 = Blue; + 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(180,0); //show coordinates printf(" x = "); tft.locate(180,12); - printf(" y = "); - - tft.locate(90,0); // -------Kirkkaushömppää-------- - printf(" B = "); - - if (q = brightness && s = 1) { - q = 0; - w = brightness; - } - if (w = brightness && s = 1) { - w = 0; - e = brightness; - } - - + printf(" y = "); + + tft.locate(85,0); + printf(" Octave = "); + tft.locate(85, 12); + printf(" Slider = "); + + + tft.locate(0,0); - printf(" MIDIMAN! "); - tft.line(0,83,239,83,White); - + printf(" MIDIMAN! "); + tft.line(0,83,239,83,White); + while (1) { - + color = White; - draw_buttons(color); - led1 = q; - led2 = w; - led3 = e; - led4 = r; - + draw_buttons(color); + + + + while (tft.is_touched(tft.get_touch())) { // touch - p = tft.get_touch(); + p = tft.get_touch(); p = tft.to_pixel(p); // convert to pixel position - - light_pressed(Red,p); // light pressed button - + + if (shift == 1) { + light_pressed2(color2, p); + } else { + light_pressed(color, p); + } + + tft.locate(210,0); printf("%3d",p.x); tft.locate(210,12); - printf("%3d",p.y); - - tft.locate(100,0); - printf("%f", brightness); + printf("%3d",p.y); + + tft.locate(160, 0); + // printf("%3d", octave); + tft.locate(160, 12); + printf("%i", slider); - } - } - - + + + } + } + + }