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