MIDI Interface in progress
Dependencies: SPI_TFT_ILI9341 TFT_fonts Touch_tft PowerControl mbed USBMIDI
main.cpp@3:c8a476a218e3, 2014-01-30 (annotated)
- Committer:
- MetropoliaMies
- Date:
- Thu Jan 30 06:30:10 2014 +0000
- Revision:
- 3:c8a476a218e3
- Parent:
- 2:478274cba6c3
- Child:
- 4:76c054f8b97e
645
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 "SPI_TFT_ILI9341.h" |
Vekotin | 0:98b5cd030eee | 3 | #include "Arial12x12.h" |
Vekotin | 0:98b5cd030eee | 4 | #include "Arial28x28.h" |
Vekotin | 0:98b5cd030eee | 5 | #include "touch_tft.h" |
Vekotin | 0:98b5cd030eee | 6 | #include "USBMIDI.h" |
Vekotin | 0:98b5cd030eee | 7 | |
Vekotin | 0:98b5cd030eee | 8 | |
Vekotin | 0:98b5cd030eee | 9 | // the TFT is connected to SPI pin 5-7 |
Vekotin | 0:98b5cd030eee | 10 | // the touch is connected to 19,20,16,17 |
Vekotin | 0:98b5cd030eee | 11 | |
Vekotin | 0:98b5cd030eee | 12 | 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 | 0:98b5cd030eee | 13 | |
MetropoliaMies | 3:c8a476a218e3 | 14 | PwmOut led1(LED1); |
MetropoliaMies | 3:c8a476a218e3 | 15 | PwmOut led2(LED2); |
MetropoliaMies | 3:c8a476a218e3 | 16 | PwmOut led3(LED3); |
MetropoliaMies | 3:c8a476a218e3 | 17 | PwmOut led4(LED4); |
MetropoliaMies | 3:c8a476a218e3 | 18 | int q,w,e,r,s; |
MetropoliaMies | 3:c8a476a218e3 | 19 | |
MetropoliaMies | 3:c8a476a218e3 | 20 | float brightness = 0.0; |
Vekotin | 0:98b5cd030eee | 21 | |
Vekotin | 1:7e2d93d70d2b | 22 | void buttons(int b, unsigned short color) { //button field |
Vekotin | 1:7e2d93d70d2b | 23 | |
Vekotin | 1:7e2d93d70d2b | 24 | if (b == 1) { |
Vekotin | 1:7e2d93d70d2b | 25 | tft.fillrect(3,88,78,158,color); |
Vekotin | 1:7e2d93d70d2b | 26 | } |
Vekotin | 1:7e2d93d70d2b | 27 | if (b == 2) { |
Vekotin | 1:7e2d93d70d2b | 28 | tft.fillrect(83,88,158,158,color); |
Vekotin | 1:7e2d93d70d2b | 29 | } |
Vekotin | 1:7e2d93d70d2b | 30 | if (b == 3) { |
Vekotin | 1:7e2d93d70d2b | 31 | tft.fillrect(163,88,238,158,color); |
Vekotin | 1:7e2d93d70d2b | 32 | } |
Vekotin | 1:7e2d93d70d2b | 33 | |
Vekotin | 1:7e2d93d70d2b | 34 | if (b == 4) { |
Vekotin | 1:7e2d93d70d2b | 35 | tft.fillrect(3,163,78,238,color); |
Vekotin | 1:7e2d93d70d2b | 36 | } |
Vekotin | 1:7e2d93d70d2b | 37 | if (b == 5) { |
Vekotin | 1:7e2d93d70d2b | 38 | tft.fillrect(83,163,158,238,color); |
Vekotin | 1:7e2d93d70d2b | 39 | } |
Vekotin | 1:7e2d93d70d2b | 40 | if (b == 6) { |
Vekotin | 1:7e2d93d70d2b | 41 | tft.fillrect(163,163,238,238,color); |
Vekotin | 1:7e2d93d70d2b | 42 | } |
Vekotin | 1:7e2d93d70d2b | 43 | |
Vekotin | 1:7e2d93d70d2b | 44 | if (b == 7) { |
Vekotin | 1:7e2d93d70d2b | 45 | tft.fillrect(3,243,78,318,color); |
Vekotin | 1:7e2d93d70d2b | 46 | } |
Vekotin | 1:7e2d93d70d2b | 47 | if (b == 8) { |
Vekotin | 1:7e2d93d70d2b | 48 | tft.fillrect(83,243,158,318,color); |
Vekotin | 1:7e2d93d70d2b | 49 | } |
Vekotin | 1:7e2d93d70d2b | 50 | if (b == 9) { |
Vekotin | 1:7e2d93d70d2b | 51 | tft.fillrect(163,243,238,318,color); |
Vekotin | 1:7e2d93d70d2b | 52 | } |
Vekotin | 1:7e2d93d70d2b | 53 | |
Vekotin | 1:7e2d93d70d2b | 54 | } |
Vekotin | 1:7e2d93d70d2b | 55 | |
Vekotin | 1:7e2d93d70d2b | 56 | void draw_buttons(unsigned short color) { |
Vekotin | 1:7e2d93d70d2b | 57 | |
Vekotin | 1:7e2d93d70d2b | 58 | unsigned int i = 1; |
Vekotin | 1:7e2d93d70d2b | 59 | |
Vekotin | 1:7e2d93d70d2b | 60 | for (i = 1; i<10; i++){ //draw buttons |
Vekotin | 1:7e2d93d70d2b | 61 | buttons(i, color); |
Vekotin | 1:7e2d93d70d2b | 62 | } |
Vekotin | 1:7e2d93d70d2b | 63 | |
Vekotin | 1:7e2d93d70d2b | 64 | } |
Vekotin | 0:98b5cd030eee | 65 | |
Vekotin | 2:478274cba6c3 | 66 | void light_pressed(unsigned short color, point p) |
Vekotin | 2:478274cba6c3 | 67 | { |
Vekotin | 2:478274cba6c3 | 68 | |
Vekotin | 2:478274cba6c3 | 69 | if (p.y > 88 && p.y < 158) { //ROW A |
Vekotin | 2:478274cba6c3 | 70 | if (p.x > 3 && p.x < 78) { //button 1 |
Vekotin | 2:478274cba6c3 | 71 | buttons(1, color); |
Vekotin | 2:478274cba6c3 | 72 | } |
Vekotin | 2:478274cba6c3 | 73 | if (p.x > 83 && p.x < 158) { //button 2 |
Vekotin | 2:478274cba6c3 | 74 | buttons(2, color); |
Vekotin | 2:478274cba6c3 | 75 | } |
Vekotin | 2:478274cba6c3 | 76 | if (p.x > 163 && p.x < 238) { //button 3 |
Vekotin | 2:478274cba6c3 | 77 | buttons(3, color); |
MetropoliaMies | 3:c8a476a218e3 | 78 | brightness += 0.01; |
Vekotin | 2:478274cba6c3 | 79 | } |
Vekotin | 2:478274cba6c3 | 80 | } |
Vekotin | 2:478274cba6c3 | 81 | |
Vekotin | 2:478274cba6c3 | 82 | if (p.y > 163 && p.y < 238) { //ROW B |
Vekotin | 2:478274cba6c3 | 83 | if (p.x > 3 && p.x < 78) { //button 4 |
Vekotin | 2:478274cba6c3 | 84 | buttons(4, color); |
MetropoliaMies | 3:c8a476a218e3 | 85 | s = 1; |
Vekotin | 2:478274cba6c3 | 86 | } |
Vekotin | 2:478274cba6c3 | 87 | if (p.x > 83 && p.x < 158) { //button 5 |
Vekotin | 2:478274cba6c3 | 88 | buttons(5, color); |
MetropoliaMies | 3:c8a476a218e3 | 89 | led1 = 0.5; |
Vekotin | 2:478274cba6c3 | 90 | } |
Vekotin | 2:478274cba6c3 | 91 | if (p.x > 163 && p.x < 238) { //button 6 |
Vekotin | 2:478274cba6c3 | 92 | buttons(6, color); |
MetropoliaMies | 3:c8a476a218e3 | 93 | s = 2; |
Vekotin | 2:478274cba6c3 | 94 | } |
Vekotin | 2:478274cba6c3 | 95 | } |
Vekotin | 2:478274cba6c3 | 96 | |
Vekotin | 2:478274cba6c3 | 97 | if (p.y > 243 && p.y < 318) { //ROW C |
Vekotin | 2:478274cba6c3 | 98 | if (p.x > 3 && p.x < 78) { //button 7 |
Vekotin | 2:478274cba6c3 | 99 | buttons(7, color); |
Vekotin | 2:478274cba6c3 | 100 | } |
Vekotin | 2:478274cba6c3 | 101 | if (p.x > 83 && p.x < 158) { //button 8 |
Vekotin | 2:478274cba6c3 | 102 | buttons(8, color); |
Vekotin | 2:478274cba6c3 | 103 | } |
Vekotin | 2:478274cba6c3 | 104 | if (p.x > 163 && p.x < 238) { //button 9 |
Vekotin | 2:478274cba6c3 | 105 | buttons(9, color); |
MetropoliaMies | 3:c8a476a218e3 | 106 | brightness -= 0.01; |
Vekotin | 2:478274cba6c3 | 107 | } |
Vekotin | 2:478274cba6c3 | 108 | } |
Vekotin | 2:478274cba6c3 | 109 | } |
Vekotin | 2:478274cba6c3 | 110 | |
Vekotin | 2:478274cba6c3 | 111 | int main() { |
Vekotin | 2:478274cba6c3 | 112 | |
Vekotin | 2:478274cba6c3 | 113 | // PERUSPOHJA, ÄLÄ MUOKKAA! |
Vekotin | 0:98b5cd030eee | 114 | |
Vekotin | 0:98b5cd030eee | 115 | point p; |
Vekotin | 0:98b5cd030eee | 116 | unsigned short color = White; |
Vekotin | 0:98b5cd030eee | 117 | |
Vekotin | 0:98b5cd030eee | 118 | tft.claim(stdout); // send stdout to the TFT display |
Vekotin | 0:98b5cd030eee | 119 | tft.background(Black); // set background to black |
Vekotin | 0:98b5cd030eee | 120 | tft.foreground(White); // set chars to white |
Vekotin | 0:98b5cd030eee | 121 | tft.cls(); // clear the screen |
Vekotin | 2:478274cba6c3 | 122 | tft.set_font((unsigned char*) Arial12x12); // select the font |
Vekotin | 0:98b5cd030eee | 123 | |
Vekotin | 0:98b5cd030eee | 124 | tft.set_orientation(0); |
Vekotin | 0:98b5cd030eee | 125 | tft.calibrate(); |
Vekotin | 0:98b5cd030eee | 126 | |
Vekotin | 2:478274cba6c3 | 127 | |
Vekotin | 2:478274cba6c3 | 128 | tft.locate(180,0); //show coordinates |
Vekotin | 2:478274cba6c3 | 129 | printf(" x = "); |
Vekotin | 2:478274cba6c3 | 130 | tft.locate(180,12); |
Vekotin | 2:478274cba6c3 | 131 | printf(" y = "); |
Vekotin | 2:478274cba6c3 | 132 | |
MetropoliaMies | 3:c8a476a218e3 | 133 | tft.locate(90,0); // -------Kirkkaushömppää-------- |
MetropoliaMies | 3:c8a476a218e3 | 134 | printf(" B = "); |
MetropoliaMies | 3:c8a476a218e3 | 135 | |
MetropoliaMies | 3:c8a476a218e3 | 136 | if (q = brightness && s = 1) { |
MetropoliaMies | 3:c8a476a218e3 | 137 | q = 0; |
MetropoliaMies | 3:c8a476a218e3 | 138 | w = brightness; |
MetropoliaMies | 3:c8a476a218e3 | 139 | } |
MetropoliaMies | 3:c8a476a218e3 | 140 | if (w = brightness && s = 1) { |
MetropoliaMies | 3:c8a476a218e3 | 141 | w = 0; |
MetropoliaMies | 3:c8a476a218e3 | 142 | e = brightness; |
MetropoliaMies | 3:c8a476a218e3 | 143 | } |
MetropoliaMies | 3:c8a476a218e3 | 144 | |
MetropoliaMies | 3:c8a476a218e3 | 145 | |
Vekotin | 0:98b5cd030eee | 146 | tft.locate(0,0); |
Vekotin | 1:7e2d93d70d2b | 147 | printf(" MIDIMAN! "); |
Vekotin | 1:7e2d93d70d2b | 148 | tft.line(0,83,239,83,White); |
Vekotin | 0:98b5cd030eee | 149 | |
Vekotin | 0:98b5cd030eee | 150 | while (1) { |
Vekotin | 0:98b5cd030eee | 151 | |
Vekotin | 0:98b5cd030eee | 152 | color = White; |
MetropoliaMies | 3:c8a476a218e3 | 153 | draw_buttons(color); |
MetropoliaMies | 3:c8a476a218e3 | 154 | led1 = q; |
MetropoliaMies | 3:c8a476a218e3 | 155 | led2 = w; |
MetropoliaMies | 3:c8a476a218e3 | 156 | led3 = e; |
MetropoliaMies | 3:c8a476a218e3 | 157 | led4 = r; |
Vekotin | 1:7e2d93d70d2b | 158 | |
Vekotin | 1:7e2d93d70d2b | 159 | while (tft.is_touched(tft.get_touch())) { // touch |
Vekotin | 2:478274cba6c3 | 160 | p = tft.get_touch(); |
Vekotin | 2:478274cba6c3 | 161 | p = tft.to_pixel(p); // convert to pixel position |
Vekotin | 2:478274cba6c3 | 162 | |
Vekotin | 2:478274cba6c3 | 163 | light_pressed(Red,p); // light pressed button |
Vekotin | 1:7e2d93d70d2b | 164 | |
MetropoliaMies | 3:c8a476a218e3 | 165 | tft.locate(210,0); |
Vekotin | 2:478274cba6c3 | 166 | printf("%3d",p.x); |
MetropoliaMies | 3:c8a476a218e3 | 167 | tft.locate(210,12); |
MetropoliaMies | 3:c8a476a218e3 | 168 | printf("%3d",p.y); |
MetropoliaMies | 3:c8a476a218e3 | 169 | |
MetropoliaMies | 3:c8a476a218e3 | 170 | tft.locate(100,0); |
MetropoliaMies | 3:c8a476a218e3 | 171 | printf("%f", brightness); |
Vekotin | 2:478274cba6c3 | 172 | |
Vekotin | 2:478274cba6c3 | 173 | } |
Vekotin | 2:478274cba6c3 | 174 | } |
Vekotin | 0:98b5cd030eee | 175 | |
Vekotin | 2:478274cba6c3 | 176 | |
Vekotin | 0:98b5cd030eee | 177 | } |
Vekotin | 0:98b5cd030eee | 178 | |
Vekotin | 0:98b5cd030eee | 179 | |
Vekotin | 0:98b5cd030eee | 180 | |
Vekotin | 0:98b5cd030eee | 181 |