midi device enerates tones according freedom rotation
Dependencies: MMA8451Q USBDevice mbed TSI
Diff: main.cpp
- Revision:
- 4:9c81faf1b372
- Parent:
- 3:e0684e01fca1
- Child:
- 5:421d532c6403
--- a/main.cpp Mon Aug 19 08:06:17 2013 +0000 +++ b/main.cpp Mon Aug 19 12:16:44 2013 +0000 @@ -1,6 +1,7 @@ #include "mbed.h" #include "MMA8451Q.h" #include "USBMIDI.h" +#include "TSISensor.h" #define MMA8451_I2C_ADDRESS (0x1d<<1) @@ -36,8 +37,20 @@ #define NH2 71 #define NC3 72 +/* tempo delays */ +#define EITH 5 +#define QUATER 25 +#define HALF 50 +#define FULL 75 + +#define T_EITH 0.08 /* set the basic dealy here */ +#define T_QUATER (T_EITH*2) +#define T_HALF (T_QUATER*2) +#define T_FULL (T_HALF*2) + Serial pc(USBTX,USBRX); USBMIDI midi; +TSISensor tsi; void show_message(MIDIMessage msg) { @@ -65,17 +78,44 @@ int note=48; float notechng; + float fpitch; + int tempo; + float pause = T_HALF; MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS); midi.attach(show_message); // call back for messages received - + while (1) { - +#if 0 + /* test pitch - commented in in - endif*/ + midi.write(MIDIMessage::NoteOn(57)); + for(int c=-8000; c<8000; c= c+100){ + + midi.write(MIDIMessage::PitchWheel(c)); + pc.printf("Pitch: %d \n", c); + } + midi.write(MIDIMessage::NoteOff(57)); + wait(0.5); +#endif + + /* read note */ notechng = 1 - acc.getAccX(); - pc.printf("ZZ: %f, XX: %f, YY: %f, Note: %d \n",(1 - acc.getAccZ()), notechng, (1 - acc.getAccY()), note); + /* get pitch */ + fpitch = acc.getAccY()*100; + + /* get tempo */ + tempo =int(tsi.readPercentage() * 100); + + pause = T_EITH; + if(tempo > QUATER) pause = T_QUATER; + if(tempo > HALF) pause = T_HALF; + if(tempo > FULL) pause = T_FULL; + + pc.printf("pause: %f, note: %f, pitch: %d \n",pause, note, (int)fpitch*100); midi.write(MIDIMessage::NoteOff(note)); + wait(pause); if(notechng > C1) note= NC1; if(notechng > D1) note= ND1; @@ -94,7 +134,9 @@ if(notechng > C3) note= NC3; midi.write(MIDIMessage::NoteOn(note)); - wait(0.1); + midi.write(MIDIMessage::PitchWheel(int(fpitch))); + + wait(pause); } } \ No newline at end of file