MIDI Interface in progress
Dependencies: SPI_TFT_ILI9341 TFT_fonts Touch_tft PowerControl mbed USBMIDI
main.cpp@12:f78afb23f7e2, 2014-02-13 (annotated)
- Committer:
- tanssisatu
- Date:
- Thu Feb 13 07:36:00 2014 +0000
- Revision:
- 12:f78afb23f7e2
- Parent:
- 11:258abdee25b1
- Child:
- 13:f72d45d919b4
power management
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" |
Vekotin | 0:98b5cd030eee | 4 | #include "USBMIDI.h" |
MetropoliaMies | 4:76c054f8b97e | 5 | #include "light_pressed.h" |
tanssisatu | 12:f78afb23f7e2 | 6 | #include "PowerControl/PowerControl.h" |
tanssisatu | 12:f78afb23f7e2 | 7 | #include "PowerControl/EthernetPowerControl.h" |
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 | 10:ff7cdaeb8b9a | 12 | //Serial pc(USBTX, USBRX); |
Vekotin | 0:98b5cd030eee | 13 | |
MetropoliaMies | 6:17e0520e346f | 14 | DigitalIn key[9] = {p22, p23, p24, p25, p26, p27, p28, p29, p30}; //inputit |
MetropoliaMies | 6:17e0520e346f | 15 | |
MetropoliaMies | 6:17e0520e346f | 16 | int input = 0; |
tanssisatu | 7:4aec4a6acac2 | 17 | int i; |
MetropoliaMies | 6:17e0520e346f | 18 | int painetut_nappaimet[9] = {0}; |
MetropoliaMies | 6:17e0520e346f | 19 | |
Vekotin | 10:ff7cdaeb8b9a | 20 | USBMIDI midi; |
MetropoliaMies | 6:17e0520e346f | 21 | |
tanssisatu | 12:f78afb23f7e2 | 22 | // Function to power down magic USB interface chip with new firmware |
tanssisatu | 12:f78afb23f7e2 | 23 | #define USR_POWERDOWN (0x104) |
tanssisatu | 12:f78afb23f7e2 | 24 | int semihost_powerdown() { |
tanssisatu | 12:f78afb23f7e2 | 25 | uint32_t arg; |
tanssisatu | 12:f78afb23f7e2 | 26 | return __semihost(USR_POWERDOWN, &arg); |
tanssisatu | 12:f78afb23f7e2 | 27 | } |
tanssisatu | 12:f78afb23f7e2 | 28 | |
MetropoliaMies | 4:76c054f8b97e | 29 | void draw_buttons(unsigned short color) |
MetropoliaMies | 4:76c054f8b97e | 30 | { |
MetropoliaMies | 4:76c054f8b97e | 31 | unsigned int i = 0; |
Vekotin | 2:478274cba6c3 | 32 | |
MetropoliaMies | 4:76c054f8b97e | 33 | for (i = 0; i<10; i++) { //draw buttons |
MetropoliaMies | 4:76c054f8b97e | 34 | tft.locate(10,50); |
MetropoliaMies | 4:76c054f8b97e | 35 | printf("Shift"); |
tanssisatu | 7:4aec4a6acac2 | 36 | buttons(i, color); |
Vekotin | 2:478274cba6c3 | 37 | } |
Vekotin | 2:478274cba6c3 | 38 | } |
Vekotin | 2:478274cba6c3 | 39 | |
tanssisatu | 7:4aec4a6acac2 | 40 | void nine_keys(void) |
tanssisatu | 7:4aec4a6acac2 | 41 | { |
Vekotin | 10:ff7cdaeb8b9a | 42 | for (i = 0; i < 9; i++) { |
Vekotin | 10:ff7cdaeb8b9a | 43 | if (!key[i].read() & !painetut_nappaimet[i]) { |
Vekotin | 10:ff7cdaeb8b9a | 44 | midi.write(MIDIMessage::NoteOn(36 + i + Oct)); |
Vekotin | 10:ff7cdaeb8b9a | 45 | painetut_nappaimet[i] = true; |
Vekotin | 10:ff7cdaeb8b9a | 46 | } |
Vekotin | 10:ff7cdaeb8b9a | 47 | } |
tanssisatu | 7:4aec4a6acac2 | 48 | |
Vekotin | 10:ff7cdaeb8b9a | 49 | for (i = 0; i < 9; i++) { |
Vekotin | 10:ff7cdaeb8b9a | 50 | if (key[i].read()) midi.write(MIDIMessage::NoteOff(36 + i + Oct)); |
Vekotin | 10:ff7cdaeb8b9a | 51 | } |
Vekotin | 10:ff7cdaeb8b9a | 52 | |
Vekotin | 10:ff7cdaeb8b9a | 53 | for (i = 0; i < 9; i++) { |
Vekotin | 10:ff7cdaeb8b9a | 54 | if (key[i].read()) painetut_nappaimet[i] = false; |
Vekotin | 10:ff7cdaeb8b9a | 55 | } |
tanssisatu | 7:4aec4a6acac2 | 56 | } |
tanssisatu | 7:4aec4a6acac2 | 57 | |
tanssisatu | 7:4aec4a6acac2 | 58 | |
tanssisatu | 12:f78afb23f7e2 | 59 | void powerdown(void) |
tanssisatu | 12:f78afb23f7e2 | 60 | { |
tanssisatu | 12:f78afb23f7e2 | 61 | PHY_PowerDown(); |
tanssisatu | 12:f78afb23f7e2 | 62 | semihost_powerdown(); |
tanssisatu | 12:f78afb23f7e2 | 63 | //Peripheral_PowerDown(0xFFFF7FFF); |
tanssisatu | 12:f78afb23f7e2 | 64 | } |
tanssisatu | 12:f78afb23f7e2 | 65 | |
tanssisatu | 12:f78afb23f7e2 | 66 | |
MetropoliaMies | 4:76c054f8b97e | 67 | int main() |
MetropoliaMies | 4:76c054f8b97e | 68 | { |
Vekotin | 2:478274cba6c3 | 69 | // PERUSPOHJA, ÄLÄ MUOKKAA! |
tanssisatu | 12:f78afb23f7e2 | 70 | powerdown(); |
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 | |
Vekotin | 2:478274cba6c3 | 83 | tft.locate(180,0); //show coordinates |
Vekotin | 2:478274cba6c3 | 84 | printf(" x = "); |
Vekotin | 2:478274cba6c3 | 85 | tft.locate(180,12); |
MetropoliaMies | 4:76c054f8b97e | 86 | printf(" y = "); |
MetropoliaMies | 4:76c054f8b97e | 87 | |
MetropoliaMies | 4:76c054f8b97e | 88 | tft.locate(85,0); |
MetropoliaMies | 4:76c054f8b97e | 89 | printf(" Octave = "); |
MetropoliaMies | 4:76c054f8b97e | 90 | tft.locate(85, 12); |
MetropoliaMies | 4:76c054f8b97e | 91 | printf(" Slider = "); |
MetropoliaMies | 4:76c054f8b97e | 92 | |
Vekotin | 0:98b5cd030eee | 93 | tft.locate(0,0); |
MetropoliaMies | 4:76c054f8b97e | 94 | printf(" MIDIMAN! "); |
MetropoliaMies | 4:76c054f8b97e | 95 | tft.line(0,83,239,83,White); |
MetropoliaMies | 11:258abdee25b1 | 96 | |
MetropoliaMies | 11:258abdee25b1 | 97 | tft.locate(180,270); |
MetropoliaMies | 11:258abdee25b1 | 98 | tft.foreground(Black); |
MetropoliaMies | 11:258abdee25b1 | 99 | tft.background(White); |
MetropoliaMies | 11:258abdee25b1 | 100 | printf("Octave"); |
MetropoliaMies | 11:258abdee25b1 | 101 | tft.locate(190,282); |
MetropoliaMies | 11:258abdee25b1 | 102 | printf("Up"); |
MetropoliaMies | 11:258abdee25b1 | 103 | tft.locate(100,270); |
MetropoliaMies | 11:258abdee25b1 | 104 | printf("Octave"); |
MetropoliaMies | 11:258abdee25b1 | 105 | tft.locate(102,282); |
MetropoliaMies | 11:258abdee25b1 | 106 | printf("Down"); |
MetropoliaMies | 4:76c054f8b97e | 107 | |
MetropoliaMies | 11:258abdee25b1 | 108 | tft.background(Black); // set background to black |
MetropoliaMies | 11:258abdee25b1 | 109 | tft.foreground(White); // set chars to white |
MetropoliaMies | 11:258abdee25b1 | 110 | |
MetropoliaMies | 5:8e13103b41be | 111 | |
Vekotin | 0:98b5cd030eee | 112 | while (1) { |
MetropoliaMies | 4:76c054f8b97e | 113 | |
Vekotin | 0:98b5cd030eee | 114 | color = White; |
MetropoliaMies | 4:76c054f8b97e | 115 | draw_buttons(color); |
MetropoliaMies | 4:76c054f8b97e | 116 | |
Vekotin | 1:7e2d93d70d2b | 117 | while (tft.is_touched(tft.get_touch())) { // touch |
MetropoliaMies | 4:76c054f8b97e | 118 | p = tft.get_touch(); |
Vekotin | 2:478274cba6c3 | 119 | p = tft.to_pixel(p); // convert to pixel position |
MetropoliaMies | 4:76c054f8b97e | 120 | |
MetropoliaMies | 3:c8a476a218e3 | 121 | tft.locate(210,0); |
Vekotin | 2:478274cba6c3 | 122 | printf("%3d",p.x); |
MetropoliaMies | 3:c8a476a218e3 | 123 | tft.locate(210,12); |
MetropoliaMies | 4:76c054f8b97e | 124 | printf("%3d",p.y); |
MetropoliaMies | 4:76c054f8b97e | 125 | |
tanssisatu | 7:4aec4a6acac2 | 126 | light_pressed(Red,p); |
Vekotin | 10:ff7cdaeb8b9a | 127 | |
MetropoliaMies | 4:76c054f8b97e | 128 | tft.locate(160, 0); |
tanssisatu | 9:df3bff3a0b76 | 129 | printf("%i", Oct); |
MetropoliaMies | 4:76c054f8b97e | 130 | tft.locate(160, 12); |
MetropoliaMies | 4:76c054f8b97e | 131 | printf("%i", slider); |
MetropoliaMies | 4:76c054f8b97e | 132 | |
tanssisatu | 7:4aec4a6acac2 | 133 | nine_keys(); |
MetropoliaMies | 6:17e0520e346f | 134 | } |
tanssisatu | 7:4aec4a6acac2 | 135 | |
tanssisatu | 7:4aec4a6acac2 | 136 | nine_keys(); |
MetropoliaMies | 6:17e0520e346f | 137 | } |
Vekotin | 0:98b5cd030eee | 138 | } |
Vekotin | 0:98b5cd030eee | 139 | |
Vekotin | 0:98b5cd030eee | 140 | |
Vekotin | 0:98b5cd030eee | 141 | |
Vekotin | 0:98b5cd030eee | 142 |