MIDI Interface in progress

Dependencies:   SPI_TFT_ILI9341 TFT_fonts Touch_tft PowerControl mbed USBMIDI

Committer:
Vekotin
Date:
Thu Jan 16 07:48:24 2014 +0000
Revision:
0:98b5cd030eee
Child:
1:7e2d93d70d2b
MIDI interface, joka ei toimi

Who changed what in which revision?

UserRevisionLine numberNew 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
Vekotin 0:98b5cd030eee 14 /* void show_message(MIDIMessage msg) {
Vekotin 0:98b5cd030eee 15 switch (msg.type()) {
Vekotin 0:98b5cd030eee 16 case MIDIMessage::NoteOnType:
Vekotin 0:98b5cd030eee 17 printf("NoteOn key:%d, velocity: %d, channel: %d\n", msg.key(), msg.velocity(), msg.channel());
Vekotin 0:98b5cd030eee 18 break;
Vekotin 0:98b5cd030eee 19 case MIDIMessage::NoteOffType:
Vekotin 0:98b5cd030eee 20 printf("NoteOff key:%d, velocity: %d, channel: %d\n", msg.key(), msg.velocity(), msg.channel());
Vekotin 0:98b5cd030eee 21 break;
Vekotin 0:98b5cd030eee 22 case MIDIMessage::ControlChangeType:
Vekotin 0:98b5cd030eee 23 printf("ControlChange controller: %d, data: %d\n", msg.controller(), msg.value());
Vekotin 0:98b5cd030eee 24 break;
Vekotin 0:98b5cd030eee 25 case MIDIMessage::PitchWheelType:
Vekotin 0:98b5cd030eee 26 printf("PitchWheel channel: %d, pitch: %d\n", msg.channel(), msg.pitch());
Vekotin 0:98b5cd030eee 27 break;
Vekotin 0:98b5cd030eee 28 default:
Vekotin 0:98b5cd030eee 29 printf("Another message\n");
Vekotin 0:98b5cd030eee 30 }
Vekotin 0:98b5cd030eee 31 }
Vekotin 0:98b5cd030eee 32
Vekotin 0:98b5cd030eee 33 USBMIDI midi; */
Vekotin 0:98b5cd030eee 34
Vekotin 0:98b5cd030eee 35 int main() {
Vekotin 0:98b5cd030eee 36
Vekotin 0:98b5cd030eee 37 point p;
Vekotin 0:98b5cd030eee 38 unsigned short color = White;
Vekotin 0:98b5cd030eee 39
Vekotin 0:98b5cd030eee 40 tft.claim(stdout); // send stdout to the TFT display
Vekotin 0:98b5cd030eee 41 tft.background(Black); // set background to black
Vekotin 0:98b5cd030eee 42 tft.foreground(White); // set chars to white
Vekotin 0:98b5cd030eee 43 tft.cls(); // clear the screen
Vekotin 0:98b5cd030eee 44 tft.set_font((unsigned char*) Arial28x28); // select the font
Vekotin 0:98b5cd030eee 45
Vekotin 0:98b5cd030eee 46 tft.set_orientation(0);
Vekotin 0:98b5cd030eee 47 tft.calibrate();
Vekotin 0:98b5cd030eee 48
Vekotin 0:98b5cd030eee 49 tft.locate(0,0);
Vekotin 0:98b5cd030eee 50 printf(" HOPPODIHOI! ");
Vekotin 0:98b5cd030eee 51
Vekotin 0:98b5cd030eee 52 while (1) {
Vekotin 0:98b5cd030eee 53
Vekotin 0:98b5cd030eee 54 color = White;
Vekotin 0:98b5cd030eee 55 tft.fillrect(20,140,220,180,color);
Vekotin 0:98b5cd030eee 56
Vekotin 0:98b5cd030eee 57 p = tft.get_touch();
Vekotin 0:98b5cd030eee 58 if (tft.is_touched(p)) { // touch
Vekotin 0:98b5cd030eee 59
Vekotin 0:98b5cd030eee 60 p = tft.to_pixel(p); // convert to pixel pos
Vekotin 0:98b5cd030eee 61 if (p.y > 140 && p.y < 180) { // a button field
Vekotin 0:98b5cd030eee 62 if (p.x > 20 && p.x < 220) {
Vekotin 0:98b5cd030eee 63 color = Cyan;
Vekotin 0:98b5cd030eee 64 tft.fillrect(20,140,220,180,color);
Vekotin 0:98b5cd030eee 65 }
Vekotin 0:98b5cd030eee 66 }
Vekotin 0:98b5cd030eee 67 }
Vekotin 0:98b5cd030eee 68
Vekotin 0:98b5cd030eee 69 }
Vekotin 0:98b5cd030eee 70
Vekotin 0:98b5cd030eee 71
Vekotin 0:98b5cd030eee 72
Vekotin 0:98b5cd030eee 73 /*
Vekotin 0:98b5cd030eee 74 midi.attach(show_message); // call back for messages received
Vekotin 0:98b5cd030eee 75 while (1) {
Vekotin 0:98b5cd030eee 76 for(int i=48; i<83; i++) { // send some messages!
Vekotin 0:98b5cd030eee 77 midi.write(MIDIMessage::NoteOn(i));
Vekotin 0:98b5cd030eee 78 wait(0.25);
Vekotin 0:98b5cd030eee 79 midi.write(MIDIMessage::NoteOff(i));
Vekotin 0:98b5cd030eee 80 wait(0.5);
Vekotin 0:98b5cd030eee 81 }
Vekotin 0:98b5cd030eee 82 }
Vekotin 0:98b5cd030eee 83 */
Vekotin 0:98b5cd030eee 84
Vekotin 0:98b5cd030eee 85 }
Vekotin 0:98b5cd030eee 86
Vekotin 0:98b5cd030eee 87
Vekotin 0:98b5cd030eee 88
Vekotin 0:98b5cd030eee 89