Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SPI_TFT_ILI9341 TFT_fonts Touch_tft PowerControl mbed USBMIDI
main.cpp@8:7f7c0b94815f, 2014-02-06 (annotated)
- Committer:
- MetropoliaMies
- Date:
- Thu Feb 06 09:05:42 2014 +0000
- Revision:
- 8:7f7c0b94815f
- Parent:
- 7:4aec4a6acac2
Reveritaatio 2.00015;
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 |
tanssisatu | 7:4aec4a6acac2 | 31 | buttons(i, color); |
Vekotin | 2:478274cba6c3 | 32 | |
Vekotin | 2:478274cba6c3 | 33 | } |
Vekotin | 2:478274cba6c3 | 34 | } |
Vekotin | 2:478274cba6c3 | 35 | |
tanssisatu | 7:4aec4a6acac2 | 36 | void nine_keys(void) |
tanssisatu | 7:4aec4a6acac2 | 37 | { |
tanssisatu | 7:4aec4a6acac2 | 38 | |
tanssisatu | 7:4aec4a6acac2 | 39 | // Tallentaa pitchin |
MetropoliaMies | 8:7f7c0b94815f | 40 | |
tanssisatu | 7:4aec4a6acac2 | 41 | |
tanssisatu | 7:4aec4a6acac2 | 42 | // Tallentaa painallukset |
tanssisatu | 7:4aec4a6acac2 | 43 | for (i = 0; i < 9; i++) { |
tanssisatu | 7:4aec4a6acac2 | 44 | if (input = key[i].read()) |
tanssisatu | 7:4aec4a6acac2 | 45 | painetut_nappaimet[i] = 1; |
tanssisatu | 7:4aec4a6acac2 | 46 | } |
tanssisatu | 7:4aec4a6acac2 | 47 | // Lähettään painallusten perusteella midimessagen |
tanssisatu | 7:4aec4a6acac2 | 48 | for (i = 0; i < 9; i++) { |
tanssisatu | 7:4aec4a6acac2 | 49 | if (painetut_nappaimet[i]) |
tanssisatu | 7:4aec4a6acac2 | 50 | //midi.write(MIDIMessage::Noteon(48 + i)); |
tanssisatu | 7:4aec4a6acac2 | 51 | // Debuggaus puttyyn |
tanssisatu | 7:4aec4a6acac2 | 52 | pc.printf("Digital input %d", i); //terminal viesti |
MetropoliaMies | 8:7f7c0b94815f | 53 | |
MetropoliaMies | 8:7f7c0b94815f | 54 | pc.printf(": %d\n\r", key[i].read()); |
tanssisatu | 7:4aec4a6acac2 | 55 | } |
MetropoliaMies | 8:7f7c0b94815f | 56 | |
MetropoliaMies | 8:7f7c0b94815f | 57 | |
tanssisatu | 7:4aec4a6acac2 | 58 | // Lopettaa midimessagen lähettämisen |
tanssisatu | 7:4aec4a6acac2 | 59 | for (i = 0; i < 9; i++) { |
tanssisatu | 7:4aec4a6acac2 | 60 | if (painetut_nappaimet[i]) |
tanssisatu | 7:4aec4a6acac2 | 61 | wait(0.000001);//midi.write(MIDIMessage::NoteOff(48 + i)); |
tanssisatu | 7:4aec4a6acac2 | 62 | } |
tanssisatu | 7:4aec4a6acac2 | 63 | } |
tanssisatu | 7:4aec4a6acac2 | 64 | |
tanssisatu | 7:4aec4a6acac2 | 65 | |
MetropoliaMies | 4:76c054f8b97e | 66 | int main() |
MetropoliaMies | 4:76c054f8b97e | 67 | { |
MetropoliaMies | 4:76c054f8b97e | 68 | |
Vekotin | 2:478274cba6c3 | 69 | // PERUSPOHJA, ÄLÄ MUOKKAA! |
MetropoliaMies | 4:76c054f8b97e | 70 | |
Vekotin | 0:98b5cd030eee | 71 | point p; |
Vekotin | 0:98b5cd030eee | 72 | unsigned short color = White; |
Vekotin | 0:98b5cd030eee | 73 | |
Vekotin | 0:98b5cd030eee | 74 | tft.claim(stdout); // send stdout to the TFT display |
Vekotin | 0:98b5cd030eee | 75 | tft.background(Black); // set background to black |
Vekotin | 0:98b5cd030eee | 76 | tft.foreground(White); // set chars to white |
Vekotin | 0:98b5cd030eee | 77 | tft.cls(); // clear the screen |
Vekotin | 2:478274cba6c3 | 78 | tft.set_font((unsigned char*) Arial12x12); // select the font |
MetropoliaMies | 4:76c054f8b97e | 79 | |
Vekotin | 0:98b5cd030eee | 80 | tft.set_orientation(0); |
Vekotin | 0:98b5cd030eee | 81 | tft.calibrate(); |
MetropoliaMies | 4:76c054f8b97e | 82 | |
MetropoliaMies | 4:76c054f8b97e | 83 | |
Vekotin | 2:478274cba6c3 | 84 | tft.locate(180,0); //show coordinates |
Vekotin | 2:478274cba6c3 | 85 | printf(" x = "); |
Vekotin | 2:478274cba6c3 | 86 | tft.locate(180,12); |
MetropoliaMies | 4:76c054f8b97e | 87 | printf(" y = "); |
MetropoliaMies | 4:76c054f8b97e | 88 | |
MetropoliaMies | 4:76c054f8b97e | 89 | tft.locate(85,0); |
MetropoliaMies | 4:76c054f8b97e | 90 | printf(" Octave = "); |
MetropoliaMies | 4:76c054f8b97e | 91 | tft.locate(85, 12); |
MetropoliaMies | 4:76c054f8b97e | 92 | printf(" Slider = "); |
MetropoliaMies | 4:76c054f8b97e | 93 | |
MetropoliaMies | 4:76c054f8b97e | 94 | |
MetropoliaMies | 4:76c054f8b97e | 95 | |
Vekotin | 0:98b5cd030eee | 96 | tft.locate(0,0); |
MetropoliaMies | 4:76c054f8b97e | 97 | printf(" MIDIMAN! "); |
MetropoliaMies | 4:76c054f8b97e | 98 | tft.line(0,83,239,83,White); |
MetropoliaMies | 4:76c054f8b97e | 99 | |
MetropoliaMies | 8:7f7c0b94815f | 100 | |
MetropoliaMies | 8:7f7c0b94815f | 101 | |
MetropoliaMies | 8:7f7c0b94815f | 102 | |
MetropoliaMies | 5:8e13103b41be | 103 | |
Vekotin | 0:98b5cd030eee | 104 | while (1) { |
MetropoliaMies | 4:76c054f8b97e | 105 | |
Vekotin | 0:98b5cd030eee | 106 | color = White; |
MetropoliaMies | 4:76c054f8b97e | 107 | draw_buttons(color); |
MetropoliaMies | 4:76c054f8b97e | 108 | |
MetropoliaMies | 8:7f7c0b94815f | 109 | tft.locate(180,270); |
MetropoliaMies | 8:7f7c0b94815f | 110 | tft.foreground(Black); |
MetropoliaMies | 8:7f7c0b94815f | 111 | tft.background(White); |
MetropoliaMies | 8:7f7c0b94815f | 112 | printf("Octave"); |
MetropoliaMies | 8:7f7c0b94815f | 113 | tft.locate(190,282); |
MetropoliaMies | 8:7f7c0b94815f | 114 | printf("Up"); |
MetropoliaMies | 8:7f7c0b94815f | 115 | tft.locate(100,270); |
MetropoliaMies | 8:7f7c0b94815f | 116 | printf("Octave"); |
MetropoliaMies | 8:7f7c0b94815f | 117 | tft.locate(102,282); |
MetropoliaMies | 8:7f7c0b94815f | 118 | printf("Down"); |
MetropoliaMies | 4:76c054f8b97e | 119 | |
MetropoliaMies | 8:7f7c0b94815f | 120 | tft.background(Black); // set background to black |
MetropoliaMies | 8:7f7c0b94815f | 121 | tft.foreground(White); // set chars to white |
MetropoliaMies | 4:76c054f8b97e | 122 | |
MetropoliaMies | 4:76c054f8b97e | 123 | |
Vekotin | 1:7e2d93d70d2b | 124 | while (tft.is_touched(tft.get_touch())) { // touch |
MetropoliaMies | 4:76c054f8b97e | 125 | p = tft.get_touch(); |
Vekotin | 2:478274cba6c3 | 126 | p = tft.to_pixel(p); // convert to pixel position |
MetropoliaMies | 4:76c054f8b97e | 127 | |
MetropoliaMies | 3:c8a476a218e3 | 128 | tft.locate(210,0); |
Vekotin | 2:478274cba6c3 | 129 | printf("%3d",p.x); |
MetropoliaMies | 3:c8a476a218e3 | 130 | tft.locate(210,12); |
MetropoliaMies | 4:76c054f8b97e | 131 | printf("%3d",p.y); |
MetropoliaMies | 4:76c054f8b97e | 132 | |
tanssisatu | 7:4aec4a6acac2 | 133 | light_pressed(Red,p); |
MetropoliaMies | 8:7f7c0b94815f | 134 | |
MetropoliaMies | 4:76c054f8b97e | 135 | tft.locate(160, 0); |
MetropoliaMies | 5:8e13103b41be | 136 | printf("%i", Octave); |
MetropoliaMies | 4:76c054f8b97e | 137 | tft.locate(160, 12); |
MetropoliaMies | 4:76c054f8b97e | 138 | printf("%i", slider); |
MetropoliaMies | 8:7f7c0b94815f | 139 | |
MetropoliaMies | 4:76c054f8b97e | 140 | |
MetropoliaMies | 4:76c054f8b97e | 141 | |
tanssisatu | 7:4aec4a6acac2 | 142 | nine_keys(); |
MetropoliaMies | 6:17e0520e346f | 143 | } |
tanssisatu | 7:4aec4a6acac2 | 144 | |
tanssisatu | 7:4aec4a6acac2 | 145 | nine_keys(); |
tanssisatu | 7:4aec4a6acac2 | 146 | |
MetropoliaMies | 6:17e0520e346f | 147 | } |
Vekotin | 0:98b5cd030eee | 148 | } |
Vekotin | 0:98b5cd030eee | 149 | |
Vekotin | 0:98b5cd030eee | 150 | |
Vekotin | 0:98b5cd030eee | 151 | |
Vekotin | 0:98b5cd030eee | 152 |