MIDI Interface in progress

Dependencies:   SPI_TFT_ILI9341 TFT_fonts Touch_tft PowerControl mbed USBMIDI

Committer:
MetropoliaMies
Date:
Thu Feb 13 09:04:51 2014 +0000
Revision:
13:f72d45d919b4
Parent:
12:f78afb23f7e2
Workare v4.0

Who changed what in which revision?

UserRevisionLine numberNew 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
tanssisatu 7:4aec4a6acac2 34 buttons(i, color);
MetropoliaMies 13:f72d45d919b4 35 buttons_text();
Vekotin 2:478274cba6c3 36 }
Vekotin 2:478274cba6c3 37 }
Vekotin 2:478274cba6c3 38
tanssisatu 7:4aec4a6acac2 39 void nine_keys(void)
tanssisatu 7:4aec4a6acac2 40 {
Vekotin 10:ff7cdaeb8b9a 41 for (i = 0; i < 9; i++) {
Vekotin 10:ff7cdaeb8b9a 42 if (!key[i].read() & !painetut_nappaimet[i]) {
Vekotin 10:ff7cdaeb8b9a 43 midi.write(MIDIMessage::NoteOn(36 + i + Oct));
Vekotin 10:ff7cdaeb8b9a 44 painetut_nappaimet[i] = true;
Vekotin 10:ff7cdaeb8b9a 45 }
Vekotin 10:ff7cdaeb8b9a 46 }
tanssisatu 7:4aec4a6acac2 47
Vekotin 10:ff7cdaeb8b9a 48 for (i = 0; i < 9; i++) {
Vekotin 10:ff7cdaeb8b9a 49 if (key[i].read()) midi.write(MIDIMessage::NoteOff(36 + i + Oct));
Vekotin 10:ff7cdaeb8b9a 50 }
Vekotin 10:ff7cdaeb8b9a 51
Vekotin 10:ff7cdaeb8b9a 52 for (i = 0; i < 9; i++) {
Vekotin 10:ff7cdaeb8b9a 53 if (key[i].read()) painetut_nappaimet[i] = false;
Vekotin 10:ff7cdaeb8b9a 54 }
tanssisatu 7:4aec4a6acac2 55 }
tanssisatu 7:4aec4a6acac2 56
tanssisatu 7:4aec4a6acac2 57
tanssisatu 12:f78afb23f7e2 58 void powerdown(void)
tanssisatu 12:f78afb23f7e2 59 {
MetropoliaMies 13:f72d45d919b4 60 PHY_PowerDown(); //Ethernet pois käytöstä
MetropoliaMies 13:f72d45d919b4 61 semihost_powerdown(); //USB pois käytöstä
MetropoliaMies 13:f72d45d919b4 62 Peripheral_PowerDown(0x80080); //Käyttämätön I2C pois käytöstä
tanssisatu 12:f78afb23f7e2 63 }
tanssisatu 12:f78afb23f7e2 64
tanssisatu 12:f78afb23f7e2 65
MetropoliaMies 4:76c054f8b97e 66 int main()
MetropoliaMies 4:76c054f8b97e 67 {
Vekotin 2:478274cba6c3 68 // PERUSPOHJA, ÄLÄ MUOKKAA!
tanssisatu 12:f78afb23f7e2 69 powerdown();
Vekotin 0:98b5cd030eee 70 point p;
Vekotin 0:98b5cd030eee 71 unsigned short color = White;
Vekotin 0:98b5cd030eee 72
Vekotin 0:98b5cd030eee 73 tft.claim(stdout); // send stdout to the TFT display
Vekotin 0:98b5cd030eee 74 tft.background(Black); // set background to black
Vekotin 0:98b5cd030eee 75 tft.foreground(White); // set chars to white
Vekotin 0:98b5cd030eee 76 tft.cls(); // clear the screen
Vekotin 2:478274cba6c3 77 tft.set_font((unsigned char*) Arial12x12); // select the font
MetropoliaMies 4:76c054f8b97e 78
Vekotin 0:98b5cd030eee 79 tft.set_orientation(0);
Vekotin 0:98b5cd030eee 80 tft.calibrate();
MetropoliaMies 4:76c054f8b97e 81
Vekotin 2:478274cba6c3 82 tft.locate(180,0); //show coordinates
Vekotin 2:478274cba6c3 83 printf(" x = ");
Vekotin 2:478274cba6c3 84 tft.locate(180,12);
MetropoliaMies 4:76c054f8b97e 85 printf(" y = ");
MetropoliaMies 4:76c054f8b97e 86
MetropoliaMies 4:76c054f8b97e 87 tft.locate(85,0);
MetropoliaMies 4:76c054f8b97e 88 printf(" Octave = ");
MetropoliaMies 4:76c054f8b97e 89 tft.locate(85, 12);
MetropoliaMies 4:76c054f8b97e 90 printf(" Slider = ");
MetropoliaMies 4:76c054f8b97e 91
Vekotin 0:98b5cd030eee 92 tft.locate(0,0);
MetropoliaMies 4:76c054f8b97e 93 printf(" MIDIMAN! ");
MetropoliaMies 4:76c054f8b97e 94 tft.line(0,83,239,83,White);
MetropoliaMies 11:258abdee25b1 95
MetropoliaMies 4:76c054f8b97e 96
MetropoliaMies 11:258abdee25b1 97
MetropoliaMies 5:8e13103b41be 98
Vekotin 0:98b5cd030eee 99 while (1) {
MetropoliaMies 4:76c054f8b97e 100
Vekotin 0:98b5cd030eee 101 color = White;
MetropoliaMies 4:76c054f8b97e 102 draw_buttons(color);
MetropoliaMies 4:76c054f8b97e 103
Vekotin 1:7e2d93d70d2b 104 while (tft.is_touched(tft.get_touch())) { // touch
MetropoliaMies 4:76c054f8b97e 105 p = tft.get_touch();
Vekotin 2:478274cba6c3 106 p = tft.to_pixel(p); // convert to pixel position
MetropoliaMies 4:76c054f8b97e 107
MetropoliaMies 3:c8a476a218e3 108 tft.locate(210,0);
Vekotin 2:478274cba6c3 109 printf("%3d",p.x);
MetropoliaMies 3:c8a476a218e3 110 tft.locate(210,12);
MetropoliaMies 4:76c054f8b97e 111 printf("%3d",p.y);
MetropoliaMies 4:76c054f8b97e 112
tanssisatu 7:4aec4a6acac2 113 light_pressed(Red,p);
Vekotin 10:ff7cdaeb8b9a 114
MetropoliaMies 4:76c054f8b97e 115 tft.locate(160, 0);
MetropoliaMies 13:f72d45d919b4 116 printf("C%i", oktaavi[o]);
MetropoliaMies 4:76c054f8b97e 117 tft.locate(160, 12);
MetropoliaMies 4:76c054f8b97e 118 printf("%i", slider);
MetropoliaMies 4:76c054f8b97e 119
tanssisatu 7:4aec4a6acac2 120 nine_keys();
MetropoliaMies 6:17e0520e346f 121 }
tanssisatu 7:4aec4a6acac2 122
tanssisatu 7:4aec4a6acac2 123 nine_keys();
MetropoliaMies 6:17e0520e346f 124 }
Vekotin 0:98b5cd030eee 125 }
Vekotin 0:98b5cd030eee 126
Vekotin 0:98b5cd030eee 127
Vekotin 0:98b5cd030eee 128
Vekotin 0:98b5cd030eee 129