midi device enerates tones according freedom rotation

Dependencies:   MMA8451Q USBDevice mbed TSI

Files at this revision

API Documentation at this revision

Comitter:
PavelM
Date:
Fri Aug 16 08:13:57 2013 +0000
Parent:
0:8e6b0e518883
Child:
2:c79be10b5ff3
Commit message:
midi kram

Changed in this revision

MMA8451Q.lib Show annotated file Show diff for this revision Revisions of this file
USBDevice.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MMA8451Q.lib	Fri Aug 16 08:13:57 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/JoKer/code/MMA8451Q/#2d14600116fc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBDevice.lib	Fri Aug 16 08:13:57 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/USBDevice/#6030a12b6c62
--- a/main.cpp	Tue Jul 16 13:48:47 2013 +0000
+++ b/main.cpp	Fri Aug 16 08:13:57 2013 +0000
@@ -1,24 +1,99 @@
 #include "mbed.h"
+#include "MMA8451Q.h"
+#include "USBMIDI.h"
+
+#define MMA8451_I2C_ADDRESS (0x1d<<1)
 
-DigitalOut BlueLed(LED1);
-DigitalOut GreenLed(LED2);
-DigitalOut RedLed(LED3);
+#define C1  0 
+#define D1  0.125
+#define E1  0.250
+#define F1  0.375
+#define G1  0.5
+#define A1  0.625
+#define H1  0.750
+#define C2  0.875
+#define D2  1
+#define E2  1.125
+#define F2  1.250
+#define G2  1.375
+#define A2  1.5
+#define H2  1.625
+#define C3  1.750
+
+#define NC1 44
+#define ND1 45
+#define NE1 46
+#define NF1 47
+#define NG1 48
+#define NA1 49
+#define NH1 50
+#define NC2 51
+#define ND2 52
+#define NE2 53
+#define NF2 54
+#define NG2 55
+#define NA2 56
+#define NH2 57
+#define NC3 58
 
-int main() {
-    while(1) {
-        BlueLed = 1;
-        wait(0.2);
-        BlueLed = 0;
-        wait(0.2);
+Serial pc(USBTX,USBRX);
+USBMIDI midi;
+ 
+void show_message(MIDIMessage msg) {
+    switch (msg.type()) {
+        case MIDIMessage::NoteOnType:
+            printf("NoteOn key:%d, velocity: %d, channel: %d\n", msg.key(), msg.velocity(), msg.channel());
+            break;
+        case MIDIMessage::NoteOffType:
+            printf("NoteOff key:%d, velocity: %d, channel: %d\n", msg.key(), msg.velocity(), msg.channel());
+            break;
+        case MIDIMessage::ControlChangeType:    
+            printf("ControlChange controller: %d, data: %d\n", msg.controller(), msg.value());
+            break;
+        case MIDIMessage::PitchWheelType:
+            printf("PitchWheel channel: %d, pitch: %d\n", msg.channel(), msg.pitch());
+            break;
+        default:
+            printf("Another message\n");
+    }    
+}
+ 
+
+ 
+int main() { 
+
+    int note=48;
+    float notechng;
+    
+    MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);
+             
+    midi.attach(show_message);         // call back for messages received 
+       
+    while (1) { 
+    
+        notechng = 1 - acc.getAccX();
+        pc.printf("ZZ: %f, XX: %f, YY: %f, Note: %d \n",(1 - acc.getAccZ()), notechng,  (1 - acc.getAccY()), note); 
         
-        GreenLed = 1;
-        wait(0.2);
-        GreenLed = 0;
-        wait(0.2);
+        midi.write(MIDIMessage::NoteOff(note));
         
-        RedLed = 1;
-        wait(0.2);
-        RedLed = 0;
-        wait(0.2);
+        if(notechng > C1) note= NC1;
+        if(notechng > D1) note= ND1;
+        if(notechng > E1) note= NE1;
+        if(notechng > F1) note= NF1;
+        if(notechng > G1) note= NG1;
+        if(notechng > A1) note= NA1;
+        if(notechng > H1) note= NH1;
+        if(notechng > C2) note= NC2;
+        if(notechng > D2) note= ND2;
+        if(notechng > E2) note= NE2;
+        if(notechng > F2) note= NF2;
+        if(notechng > G2) note= NG2;
+        if(notechng > A2) note= NA2;
+        if(notechng > H2) note= NH2;  
+        if(notechng > C3) note= NC3;          
+
+        midi.write(MIDIMessage::NoteOn(note));
+        wait(0.1);
+      
     }
-}
+}
\ No newline at end of file