MIDI Interface in progress
Dependencies: SPI_TFT_ILI9341 TFT_fonts Touch_tft PowerControl mbed USBMIDI
touch_interface.h@15:c297064a829b, 2014-02-24 (annotated)
- Committer:
- Vekotin
- Date:
- Mon Feb 24 09:54:44 2014 +0000
- Revision:
- 15:c297064a829b
- Child:
- 16:f4d090f1e6ed
kiguli, touchscreen vaatii updateeeeee
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Vekotin | 15:c297064a829b | 1 | #include "touch_tft.h" |
Vekotin | 15:c297064a829b | 2 | #include "SPI_TFT_ILI9341.h" |
Vekotin | 15:c297064a829b | 3 | #include "USBMIDI.h" |
Vekotin | 15:c297064a829b | 4 | |
Vekotin | 15:c297064a829b | 5 | // short slider = 8192; |
Vekotin | 15:c297064a829b | 6 | extern unsigned short Oct = 36; //default octave C1 |
Vekotin | 15:c297064a829b | 7 | |
Vekotin | 15:c297064a829b | 8 | // the TFT is connected to SPI pin 5-7 |
Vekotin | 15:c297064a829b | 9 | // the touch is connected to 19,20,17,18 |
Vekotin | 15:c297064a829b | 10 | touch_tft tft(p20,p19,p18,p17,p5, p6, p7, p14, p15, p21, "TFT"); // x+,x-,y+,y-,mosi, miso, sclk, cs, reset, dc |
Vekotin | 15:c297064a829b | 11 | DigitalIn key[9] = {p22, p23, p24, p25, p26, p27, p28, p29, p30}; //inputit |
Vekotin | 15:c297064a829b | 12 | |
Vekotin | 15:c297064a829b | 13 | unsigned char i; |
Vekotin | 15:c297064a829b | 14 | bool pressed_keys[9] = {0}; |
Vekotin | 15:c297064a829b | 15 | |
Vekotin | 15:c297064a829b | 16 | USBMIDI midi; |
Vekotin | 15:c297064a829b | 17 | |
Vekotin | 15:c297064a829b | 18 | void Nine_keys(void) |
Vekotin | 15:c297064a829b | 19 | { |
Vekotin | 15:c297064a829b | 20 | for (i = 0; i < 9; i++) { |
Vekotin | 15:c297064a829b | 21 | if (!key[i].read() & !pressed_keys[i]) { |
Vekotin | 15:c297064a829b | 22 | midi.write(MIDIMessage::NoteOn(Oct + i)); |
Vekotin | 15:c297064a829b | 23 | pressed_keys[i] = true; |
Vekotin | 15:c297064a829b | 24 | } |
Vekotin | 15:c297064a829b | 25 | if (key[i].read() & pressed_keys[i]) { |
Vekotin | 15:c297064a829b | 26 | midi.write(MIDIMessage::NoteOff(Oct + i)); |
Vekotin | 15:c297064a829b | 27 | pressed_keys[i] = false; |
Vekotin | 15:c297064a829b | 28 | } |
Vekotin | 15:c297064a829b | 29 | } |
Vekotin | 15:c297064a829b | 30 | } |
Vekotin | 15:c297064a829b | 31 | |
Vekotin | 15:c297064a829b | 32 | void Buttons(unsigned char b, unsigned short color) //Button Field |
Vekotin | 15:c297064a829b | 33 | { |
Vekotin | 15:c297064a829b | 34 | if (b == 1) { //Slider |
Vekotin | 15:c297064a829b | 35 | tft.fillrect(3,96,78,318,color); |
Vekotin | 15:c297064a829b | 36 | } |
Vekotin | 15:c297064a829b | 37 | if (b == 2) { //Octave Reset |
Vekotin | 15:c297064a829b | 38 | tft.fillrect(163,163,238,238,color); |
Vekotin | 15:c297064a829b | 39 | } |
Vekotin | 15:c297064a829b | 40 | if (b == 3) { //Octave DOWN |
Vekotin | 15:c297064a829b | 41 | tft.fillrect(83,243,158,318,color); |
Vekotin | 15:c297064a829b | 42 | } |
Vekotin | 15:c297064a829b | 43 | if (b == 4) { //Octave UP |
Vekotin | 15:c297064a829b | 44 | tft.fillrect(163,243,238,318,color); |
Vekotin | 15:c297064a829b | 45 | } |
Vekotin | 15:c297064a829b | 46 | } |
Vekotin | 15:c297064a829b | 47 | |
Vekotin | 15:c297064a829b | 48 | void Draw_buttons(unsigned short color) //Draws Button Field |
Vekotin | 15:c297064a829b | 49 | { |
Vekotin | 15:c297064a829b | 50 | unsigned char i = 0; |
Vekotin | 15:c297064a829b | 51 | |
Vekotin | 15:c297064a829b | 52 | for (i = 0; i<5; i++) { |
Vekotin | 15:c297064a829b | 53 | //tft.locate(10,50); |
Vekotin | 15:c297064a829b | 54 | Buttons(i, color); |
Vekotin | 15:c297064a829b | 55 | } |
Vekotin | 15:c297064a829b | 56 | } |
Vekotin | 15:c297064a829b | 57 | |
Vekotin | 15:c297064a829b | 58 | void Slider_action(point p) |
Vekotin | 15:c297064a829b | 59 | { |
Vekotin | 15:c297064a829b | 60 | if (p.x > 3 && p.x < 78) { //Slider |
Vekotin | 15:c297064a829b | 61 | if (p.y > 88 && p.y < 111) { |
Vekotin | 15:c297064a829b | 62 | //tft.fillrect(3,88,78,111,Red); |
Vekotin | 15:c297064a829b | 63 | midi.write(MIDIMessage::PitchWheel(8192)); |
Vekotin | 15:c297064a829b | 64 | } |
Vekotin | 15:c297064a829b | 65 | if (p.y > 111 && p.y < 134) { |
Vekotin | 15:c297064a829b | 66 | //tft.fillrect(3,111,78,134,Red); |
Vekotin | 15:c297064a829b | 67 | midi.write(MIDIMessage::PitchWheel(6400)); |
Vekotin | 15:c297064a829b | 68 | } |
Vekotin | 15:c297064a829b | 69 | if (p.y > 134 && p.y < 157) { |
Vekotin | 15:c297064a829b | 70 | //tft.fillrect(3,111,78,157,Red); |
Vekotin | 15:c297064a829b | 71 | midi.write(MIDIMessage::PitchWheel(4915)); |
Vekotin | 15:c297064a829b | 72 | } |
Vekotin | 15:c297064a829b | 73 | if (p.y > 157 && p.y < 180) { |
Vekotin | 15:c297064a829b | 74 | //tft.fillrect(3,111,78,180,Red); |
Vekotin | 15:c297064a829b | 75 | midi.write(MIDIMessage::PitchWheel(3277)); |
Vekotin | 15:c297064a829b | 76 | } |
Vekotin | 15:c297064a829b | 77 | if (p.y > 180 && p.y < 203) { |
Vekotin | 15:c297064a829b | 78 | //tft.fillrect(3,111,78,203,Red); |
Vekotin | 15:c297064a829b | 79 | midi.write(MIDIMessage::PitchWheel(1638)); |
Vekotin | 15:c297064a829b | 80 | } |
Vekotin | 15:c297064a829b | 81 | if (p.y > 203 && p.y < 226) { |
Vekotin | 15:c297064a829b | 82 | //tft.fillrect(3,111,78,226,Red); |
Vekotin | 15:c297064a829b | 83 | midi.write(MIDIMessage::PitchWheel(0)); |
Vekotin | 15:c297064a829b | 84 | } |
Vekotin | 15:c297064a829b | 85 | if (p.y > 226 && p.y < 249) { |
Vekotin | 15:c297064a829b | 86 | //tft.fillrect(3,111,78,249,Red); |
Vekotin | 15:c297064a829b | 87 | midi.write(MIDIMessage::PitchWheel(-1638)); |
Vekotin | 15:c297064a829b | 88 | } |
Vekotin | 15:c297064a829b | 89 | if (p.y > 249 && p.y < 272) { |
Vekotin | 15:c297064a829b | 90 | //tft.fillrect(3,111,78,272,Red); |
Vekotin | 15:c297064a829b | 91 | midi.write(MIDIMessage::PitchWheel(-3277)); |
Vekotin | 15:c297064a829b | 92 | } |
Vekotin | 15:c297064a829b | 93 | if (p.y > 272 && p.y < 295) { |
Vekotin | 15:c297064a829b | 94 | //tft.fillrect(3,111,78,295,Red); |
Vekotin | 15:c297064a829b | 95 | midi.write(MIDIMessage::PitchWheel(-4915)); |
Vekotin | 15:c297064a829b | 96 | } |
Vekotin | 15:c297064a829b | 97 | if (p.y > 295 && p.y < 318) { |
Vekotin | 15:c297064a829b | 98 | //tft.fillrect(3,111,78,318,Red); |
Vekotin | 15:c297064a829b | 99 | midi.write(MIDIMessage::PitchWheel(-8192)); |
Vekotin | 15:c297064a829b | 100 | } |
Vekotin | 15:c297064a829b | 101 | } |
Vekotin | 15:c297064a829b | 102 | } |
Vekotin | 15:c297064a829b | 103 | |
Vekotin | 15:c297064a829b | 104 | |
Vekotin | 15:c297064a829b | 105 | void Octave_buttons(unsigned short color, point p) |
Vekotin | 15:c297064a829b | 106 | { |
Vekotin | 15:c297064a829b | 107 | if (p.y > 243 && p.y < 318) { //ROW C |
Vekotin | 15:c297064a829b | 108 | if (p.x > 83 && p.x < 158) { //Octave down |
Vekotin | 15:c297064a829b | 109 | Buttons(3, color); |
Vekotin | 15:c297064a829b | 110 | Oct -= 12; |
Vekotin | 15:c297064a829b | 111 | wait(0.2); |
Vekotin | 15:c297064a829b | 112 | Buttons(3, White); |
Vekotin | 15:c297064a829b | 113 | } |
Vekotin | 15:c297064a829b | 114 | if (p.x > 163 && p.x < 238) { //Octave up |
Vekotin | 15:c297064a829b | 115 | Buttons(4, color); |
Vekotin | 15:c297064a829b | 116 | Oct += 12; |
Vekotin | 15:c297064a829b | 117 | wait(0.2); |
Vekotin | 15:c297064a829b | 118 | Buttons(4, White); |
Vekotin | 15:c297064a829b | 119 | } |
Vekotin | 15:c297064a829b | 120 | } |
Vekotin | 15:c297064a829b | 121 | |
Vekotin | 15:c297064a829b | 122 | if (p.y > 163 && p.y < 238) { //ROW B |
Vekotin | 15:c297064a829b | 123 | if (p.x > 163 && p.x < 238) { //Octave reset |
Vekotin | 15:c297064a829b | 124 | Oct = 36; |
Vekotin | 15:c297064a829b | 125 | Buttons(2, Cyan); |
Vekotin | 15:c297064a829b | 126 | wait(0.2); |
Vekotin | 15:c297064a829b | 127 | Buttons(2, White); |
Vekotin | 15:c297064a829b | 128 | } |
Vekotin | 15:c297064a829b | 129 | } |
Vekotin | 15:c297064a829b | 130 | |
Vekotin | 15:c297064a829b | 131 | if (Oct > 120) Oct -=12; //Octave range 12-120. |
Vekotin | 15:c297064a829b | 132 | if (Oct < 12) Oct +=12; |
Vekotin | 15:c297064a829b | 133 | } |
Vekotin | 15:c297064a829b | 134 | |
Vekotin | 15:c297064a829b | 135 | |
Vekotin | 15:c297064a829b | 136 |