MIDI Interface in progress
Dependencies: SPI_TFT_ILI9341 TFT_fonts Touch_tft PowerControl mbed USBMIDI
main.cpp@7:4aec4a6acac2, 2014-02-06 (annotated)
- Committer:
- tanssisatu
- Date:
- Thu Feb 06 08:37:47 2014 +0000
- Revision:
- 7:4aec4a6acac2
- Parent:
- 6:17e0520e346f
- Child:
- 8:7f7c0b94815f
- Child:
- 9:df3bff3a0b76
Rev 2.0002
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Vekotin | 0:98b5cd030eee | 1 | #include "mbed.h" |
MetropoliaMies | 4:76c054f8b97e | 2 | |
Vekotin | 0:98b5cd030eee | 3 | #include "Arial12x12.h" |
Vekotin | 0:98b5cd030eee | 4 | #include "Arial28x28.h" |
MetropoliaMies | 4:76c054f8b97e | 5 | |
Vekotin | 0:98b5cd030eee | 6 | #include "USBMIDI.h" |
MetropoliaMies | 4:76c054f8b97e | 7 | #include "light_pressed.h" |
Vekotin | 0:98b5cd030eee | 8 | |
Vekotin | 0:98b5cd030eee | 9 | |
Vekotin | 0:98b5cd030eee | 10 | // the TFT is connected to SPI pin 5-7 |
Vekotin | 0:98b5cd030eee | 11 | // the touch is connected to 19,20,16,17 |
Vekotin | 0:98b5cd030eee | 12 | |
Vekotin | 0:98b5cd030eee | 13 | |
Vekotin | 0:98b5cd030eee | 14 | |
MetropoliaMies | 4:76c054f8b97e | 15 | Serial pc(USBTX, USBRX); |
MetropoliaMies | 4:76c054f8b97e | 16 | |
MetropoliaMies | 6:17e0520e346f | 17 | DigitalOut led(LED1); |
MetropoliaMies | 6:17e0520e346f | 18 | DigitalIn key[9] = {p22, p23, p24, p25, p26, p27, p28, p29, p30}; //inputit |
MetropoliaMies | 6:17e0520e346f | 19 | |
MetropoliaMies | 6:17e0520e346f | 20 | int input = 0; |
tanssisatu | 7:4aec4a6acac2 | 21 | int i; |
MetropoliaMies | 6:17e0520e346f | 22 | int painetut_nappaimet[9] = {0}; |
MetropoliaMies | 6:17e0520e346f | 23 | |
MetropoliaMies | 6:17e0520e346f | 24 | |
MetropoliaMies | 4:76c054f8b97e | 25 | void draw_buttons(unsigned short color) |
MetropoliaMies | 4:76c054f8b97e | 26 | { |
Vekotin | 1:7e2d93d70d2b | 27 | |
MetropoliaMies | 4:76c054f8b97e | 28 | unsigned int i = 0; |
Vekotin | 2:478274cba6c3 | 29 | |
MetropoliaMies | 4:76c054f8b97e | 30 | for (i = 0; i<10; i++) { //draw buttons |
MetropoliaMies | 4:76c054f8b97e | 31 | tft.locate(10,50); |
MetropoliaMies | 4:76c054f8b97e | 32 | printf("Shift"); |
tanssisatu | 7:4aec4a6acac2 | 33 | buttons(i, color); |
Vekotin | 2:478274cba6c3 | 34 | |
Vekotin | 2:478274cba6c3 | 35 | } |
Vekotin | 2:478274cba6c3 | 36 | } |
Vekotin | 2:478274cba6c3 | 37 | |
tanssisatu | 7:4aec4a6acac2 | 38 | void nine_keys(void) |
tanssisatu | 7:4aec4a6acac2 | 39 | { |
tanssisatu | 7:4aec4a6acac2 | 40 | |
tanssisatu | 7:4aec4a6acac2 | 41 | // Tallentaa pitchin |
tanssisatu | 7:4aec4a6acac2 | 42 | |
tanssisatu | 7:4aec4a6acac2 | 43 | |
tanssisatu | 7:4aec4a6acac2 | 44 | // Tallentaa painallukset |
tanssisatu | 7:4aec4a6acac2 | 45 | for (i = 0; i < 9; i++) { |
tanssisatu | 7:4aec4a6acac2 | 46 | if (input = key[i].read()) |
tanssisatu | 7:4aec4a6acac2 | 47 | painetut_nappaimet[i] = 1; |
tanssisatu | 7:4aec4a6acac2 | 48 | } |
tanssisatu | 7:4aec4a6acac2 | 49 | // Lähettään painallusten perusteella midimessagen |
tanssisatu | 7:4aec4a6acac2 | 50 | for (i = 0; i < 9; i++) { |
tanssisatu | 7:4aec4a6acac2 | 51 | if (painetut_nappaimet[i]) |
tanssisatu | 7:4aec4a6acac2 | 52 | //midi.write(MIDIMessage::Noteon(48 + i)); |
tanssisatu | 7:4aec4a6acac2 | 53 | // Debuggaus puttyyn |
tanssisatu | 7:4aec4a6acac2 | 54 | pc.printf("Digital input %d", i); //terminal viesti |
tanssisatu | 7:4aec4a6acac2 | 55 | |
tanssisatu | 7:4aec4a6acac2 | 56 | pc.printf(": %d\n\r", key[i].read()); |
tanssisatu | 7:4aec4a6acac2 | 57 | } |
tanssisatu | 7:4aec4a6acac2 | 58 | |
tanssisatu | 7:4aec4a6acac2 | 59 | |
tanssisatu | 7:4aec4a6acac2 | 60 | // Lopettaa midimessagen lähettämisen |
tanssisatu | 7:4aec4a6acac2 | 61 | for (i = 0; i < 9; i++) { |
tanssisatu | 7:4aec4a6acac2 | 62 | if (painetut_nappaimet[i]) |
tanssisatu | 7:4aec4a6acac2 | 63 | wait(0.000001);//midi.write(MIDIMessage::NoteOff(48 + i)); |
tanssisatu | 7:4aec4a6acac2 | 64 | } |
tanssisatu | 7:4aec4a6acac2 | 65 | } |
tanssisatu | 7:4aec4a6acac2 | 66 | |
tanssisatu | 7:4aec4a6acac2 | 67 | |
MetropoliaMies | 4:76c054f8b97e | 68 | int main() |
MetropoliaMies | 4:76c054f8b97e | 69 | { |
MetropoliaMies | 4:76c054f8b97e | 70 | |
Vekotin | 2:478274cba6c3 | 71 | // PERUSPOHJA, ÄLÄ MUOKKAA! |
MetropoliaMies | 4:76c054f8b97e | 72 | |
Vekotin | 0:98b5cd030eee | 73 | point p; |
Vekotin | 0:98b5cd030eee | 74 | unsigned short color = White; |
Vekotin | 0:98b5cd030eee | 75 | |
Vekotin | 0:98b5cd030eee | 76 | tft.claim(stdout); // send stdout to the TFT display |
Vekotin | 0:98b5cd030eee | 77 | tft.background(Black); // set background to black |
Vekotin | 0:98b5cd030eee | 78 | tft.foreground(White); // set chars to white |
Vekotin | 0:98b5cd030eee | 79 | tft.cls(); // clear the screen |
Vekotin | 2:478274cba6c3 | 80 | tft.set_font((unsigned char*) Arial12x12); // select the font |
MetropoliaMies | 4:76c054f8b97e | 81 | |
Vekotin | 0:98b5cd030eee | 82 | tft.set_orientation(0); |
Vekotin | 0:98b5cd030eee | 83 | tft.calibrate(); |
MetropoliaMies | 4:76c054f8b97e | 84 | |
MetropoliaMies | 4:76c054f8b97e | 85 | |
Vekotin | 2:478274cba6c3 | 86 | tft.locate(180,0); //show coordinates |
Vekotin | 2:478274cba6c3 | 87 | printf(" x = "); |
Vekotin | 2:478274cba6c3 | 88 | tft.locate(180,12); |
MetropoliaMies | 4:76c054f8b97e | 89 | printf(" y = "); |
MetropoliaMies | 4:76c054f8b97e | 90 | |
MetropoliaMies | 4:76c054f8b97e | 91 | tft.locate(85,0); |
MetropoliaMies | 4:76c054f8b97e | 92 | printf(" Octave = "); |
MetropoliaMies | 4:76c054f8b97e | 93 | tft.locate(85, 12); |
MetropoliaMies | 4:76c054f8b97e | 94 | printf(" Slider = "); |
MetropoliaMies | 4:76c054f8b97e | 95 | |
MetropoliaMies | 4:76c054f8b97e | 96 | |
MetropoliaMies | 4:76c054f8b97e | 97 | |
Vekotin | 0:98b5cd030eee | 98 | tft.locate(0,0); |
MetropoliaMies | 4:76c054f8b97e | 99 | printf(" MIDIMAN! "); |
MetropoliaMies | 4:76c054f8b97e | 100 | tft.line(0,83,239,83,White); |
MetropoliaMies | 4:76c054f8b97e | 101 | |
MetropoliaMies | 5:8e13103b41be | 102 | tft.locate(163,250); |
MetropoliaMies | 5:8e13103b41be | 103 | printf("Octave up"); |
MetropoliaMies | 5:8e13103b41be | 104 | tft.locate(83,250); |
MetropoliaMies | 5:8e13103b41be | 105 | printf("Octave dwn"); |
MetropoliaMies | 5:8e13103b41be | 106 | |
Vekotin | 0:98b5cd030eee | 107 | while (1) { |
MetropoliaMies | 4:76c054f8b97e | 108 | |
Vekotin | 0:98b5cd030eee | 109 | color = White; |
MetropoliaMies | 4:76c054f8b97e | 110 | draw_buttons(color); |
MetropoliaMies | 4:76c054f8b97e | 111 | |
MetropoliaMies | 4:76c054f8b97e | 112 | |
MetropoliaMies | 4:76c054f8b97e | 113 | |
MetropoliaMies | 4:76c054f8b97e | 114 | |
Vekotin | 1:7e2d93d70d2b | 115 | while (tft.is_touched(tft.get_touch())) { // touch |
MetropoliaMies | 4:76c054f8b97e | 116 | p = tft.get_touch(); |
Vekotin | 2:478274cba6c3 | 117 | p = tft.to_pixel(p); // convert to pixel position |
MetropoliaMies | 4:76c054f8b97e | 118 | |
MetropoliaMies | 3:c8a476a218e3 | 119 | tft.locate(210,0); |
Vekotin | 2:478274cba6c3 | 120 | printf("%3d",p.x); |
MetropoliaMies | 3:c8a476a218e3 | 121 | tft.locate(210,12); |
MetropoliaMies | 4:76c054f8b97e | 122 | printf("%3d",p.y); |
MetropoliaMies | 4:76c054f8b97e | 123 | |
tanssisatu | 7:4aec4a6acac2 | 124 | light_pressed(Red,p); |
tanssisatu | 7:4aec4a6acac2 | 125 | |
MetropoliaMies | 4:76c054f8b97e | 126 | tft.locate(160, 0); |
MetropoliaMies | 5:8e13103b41be | 127 | printf("%i", Octave); |
MetropoliaMies | 4:76c054f8b97e | 128 | tft.locate(160, 12); |
MetropoliaMies | 4:76c054f8b97e | 129 | printf("%i", slider); |
tanssisatu | 7:4aec4a6acac2 | 130 | |
MetropoliaMies | 4:76c054f8b97e | 131 | |
MetropoliaMies | 4:76c054f8b97e | 132 | |
tanssisatu | 7:4aec4a6acac2 | 133 | nine_keys(); |
MetropoliaMies | 6:17e0520e346f | 134 | } |
tanssisatu | 7:4aec4a6acac2 | 135 | |
tanssisatu | 7:4aec4a6acac2 | 136 | nine_keys(); |
tanssisatu | 7:4aec4a6acac2 | 137 | |
MetropoliaMies | 6:17e0520e346f | 138 | } |
Vekotin | 0:98b5cd030eee | 139 | } |
Vekotin | 0:98b5cd030eee | 140 | |
Vekotin | 0:98b5cd030eee | 141 | |
Vekotin | 0:98b5cd030eee | 142 | |
Vekotin | 0:98b5cd030eee | 143 |