Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MMA8451Q TSI USBDevice mbed
Fork of Midiudelator by
main.cpp@2:c79be10b5ff3, 2013-08-16 (annotated)
- Committer:
- stefanimrich
- Date:
- Fri Aug 16 08:57:58 2013 +0000
- Revision:
- 2:c79be10b5ff3
- Parent:
- 1:970adc6aae96
- Child:
- 3:e0684e01fca1
update 1
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| PavelM | 0:8e6b0e518883 | 1 | #include "mbed.h" | 
| PavelM | 1:970adc6aae96 | 2 | #include "MMA8451Q.h" | 
| PavelM | 1:970adc6aae96 | 3 | #include "USBMIDI.h" | 
| PavelM | 1:970adc6aae96 | 4 | |
| PavelM | 1:970adc6aae96 | 5 | #define MMA8451_I2C_ADDRESS (0x1d<<1) | 
| PavelM | 0:8e6b0e518883 | 6 | |
| PavelM | 1:970adc6aae96 | 7 | #define C1 0 | 
| PavelM | 1:970adc6aae96 | 8 | #define D1 0.125 | 
| PavelM | 1:970adc6aae96 | 9 | #define E1 0.250 | 
| PavelM | 1:970adc6aae96 | 10 | #define F1 0.375 | 
| PavelM | 1:970adc6aae96 | 11 | #define G1 0.5 | 
| PavelM | 1:970adc6aae96 | 12 | #define A1 0.625 | 
| PavelM | 1:970adc6aae96 | 13 | #define H1 0.750 | 
| PavelM | 1:970adc6aae96 | 14 | #define C2 0.875 | 
| PavelM | 1:970adc6aae96 | 15 | #define D2 1 | 
| PavelM | 1:970adc6aae96 | 16 | #define E2 1.125 | 
| PavelM | 1:970adc6aae96 | 17 | #define F2 1.250 | 
| PavelM | 1:970adc6aae96 | 18 | #define G2 1.375 | 
| PavelM | 1:970adc6aae96 | 19 | #define A2 1.5 | 
| PavelM | 1:970adc6aae96 | 20 | #define H2 1.625 | 
| PavelM | 1:970adc6aae96 | 21 | #define C3 1.750 | 
| PavelM | 1:970adc6aae96 | 22 | |
| stefanimrich | 2:c79be10b5ff3 | 23 | #define NC1 48 | 
| stefanimrich | 2:c79be10b5ff3 | 24 | #define ND1 50 | 
| stefanimrich | 2:c79be10b5ff3 | 25 | #define NE1 52 | 
| stefanimrich | 2:c79be10b5ff3 | 26 | #define NF1 53 | 
| stefanimrich | 2:c79be10b5ff3 | 27 | #define NG1 55 | 
| stefanimrich | 2:c79be10b5ff3 | 28 | #define NA1 57 | 
| stefanimrich | 2:c79be10b5ff3 | 29 | #define NH1 59 | 
| stefanimrich | 2:c79be10b5ff3 | 30 | #define NC2 60 | 
| stefanimrich | 2:c79be10b5ff3 | 31 | #define ND2 62 | 
| stefanimrich | 2:c79be10b5ff3 | 32 | #define NE2 64 | 
| stefanimrich | 2:c79be10b5ff3 | 33 | #define NF2 65 | 
| stefanimrich | 2:c79be10b5ff3 | 34 | #define NG2 67 | 
| stefanimrich | 2:c79be10b5ff3 | 35 | #define NA2 69 | 
| stefanimrich | 2:c79be10b5ff3 | 36 | #define NH2 71 | 
| stefanimrich | 2:c79be10b5ff3 | 37 | #define NC3 72 | 
| PavelM | 0:8e6b0e518883 | 38 | |
| PavelM | 1:970adc6aae96 | 39 | Serial pc(USBTX,USBRX); | 
| PavelM | 1:970adc6aae96 | 40 | USBMIDI midi; | 
| PavelM | 1:970adc6aae96 | 41 | |
| PavelM | 1:970adc6aae96 | 42 | void show_message(MIDIMessage msg) { | 
| PavelM | 1:970adc6aae96 | 43 | switch (msg.type()) { | 
| PavelM | 1:970adc6aae96 | 44 | case MIDIMessage::NoteOnType: | 
| PavelM | 1:970adc6aae96 | 45 | printf("NoteOn key:%d, velocity: %d, channel: %d\n", msg.key(), msg.velocity(), msg.channel()); | 
| PavelM | 1:970adc6aae96 | 46 | break; | 
| PavelM | 1:970adc6aae96 | 47 | case MIDIMessage::NoteOffType: | 
| PavelM | 1:970adc6aae96 | 48 | printf("NoteOff key:%d, velocity: %d, channel: %d\n", msg.key(), msg.velocity(), msg.channel()); | 
| PavelM | 1:970adc6aae96 | 49 | break; | 
| PavelM | 1:970adc6aae96 | 50 | case MIDIMessage::ControlChangeType: | 
| PavelM | 1:970adc6aae96 | 51 | printf("ControlChange controller: %d, data: %d\n", msg.controller(), msg.value()); | 
| PavelM | 1:970adc6aae96 | 52 | break; | 
| PavelM | 1:970adc6aae96 | 53 | case MIDIMessage::PitchWheelType: | 
| PavelM | 1:970adc6aae96 | 54 | printf("PitchWheel channel: %d, pitch: %d\n", msg.channel(), msg.pitch()); | 
| PavelM | 1:970adc6aae96 | 55 | break; | 
| PavelM | 1:970adc6aae96 | 56 | default: | 
| PavelM | 1:970adc6aae96 | 57 | printf("Another message\n"); | 
| PavelM | 1:970adc6aae96 | 58 | } | 
| PavelM | 1:970adc6aae96 | 59 | } | 
| PavelM | 1:970adc6aae96 | 60 | |
| PavelM | 1:970adc6aae96 | 61 | |
| PavelM | 1:970adc6aae96 | 62 | |
| PavelM | 1:970adc6aae96 | 63 | int main() { | 
| PavelM | 1:970adc6aae96 | 64 | |
| PavelM | 1:970adc6aae96 | 65 | int note=48; | 
| PavelM | 1:970adc6aae96 | 66 | float notechng; | 
| PavelM | 1:970adc6aae96 | 67 | |
| PavelM | 1:970adc6aae96 | 68 | MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS); | 
| PavelM | 1:970adc6aae96 | 69 | |
| PavelM | 1:970adc6aae96 | 70 | midi.attach(show_message); // call back for messages received | 
| PavelM | 1:970adc6aae96 | 71 | |
| PavelM | 1:970adc6aae96 | 72 | while (1) { | 
| PavelM | 1:970adc6aae96 | 73 | |
| PavelM | 1:970adc6aae96 | 74 | notechng = 1 - acc.getAccX(); | 
| PavelM | 1:970adc6aae96 | 75 | pc.printf("ZZ: %f, XX: %f, YY: %f, Note: %d \n",(1 - acc.getAccZ()), notechng, (1 - acc.getAccY()), note); | 
| PavelM | 0:8e6b0e518883 | 76 | |
| PavelM | 1:970adc6aae96 | 77 | midi.write(MIDIMessage::NoteOff(note)); | 
| PavelM | 0:8e6b0e518883 | 78 | |
| PavelM | 1:970adc6aae96 | 79 | if(notechng > C1) note= NC1; | 
| PavelM | 1:970adc6aae96 | 80 | if(notechng > D1) note= ND1; | 
| PavelM | 1:970adc6aae96 | 81 | if(notechng > E1) note= NE1; | 
| PavelM | 1:970adc6aae96 | 82 | if(notechng > F1) note= NF1; | 
| PavelM | 1:970adc6aae96 | 83 | if(notechng > G1) note= NG1; | 
| PavelM | 1:970adc6aae96 | 84 | if(notechng > A1) note= NA1; | 
| PavelM | 1:970adc6aae96 | 85 | if(notechng > H1) note= NH1; | 
| PavelM | 1:970adc6aae96 | 86 | if(notechng > C2) note= NC2; | 
| PavelM | 1:970adc6aae96 | 87 | if(notechng > D2) note= ND2; | 
| PavelM | 1:970adc6aae96 | 88 | if(notechng > E2) note= NE2; | 
| PavelM | 1:970adc6aae96 | 89 | if(notechng > F2) note= NF2; | 
| PavelM | 1:970adc6aae96 | 90 | if(notechng > G2) note= NG2; | 
| PavelM | 1:970adc6aae96 | 91 | if(notechng > A2) note= NA2; | 
| PavelM | 1:970adc6aae96 | 92 | if(notechng > H2) note= NH2; | 
| PavelM | 1:970adc6aae96 | 93 | if(notechng > C3) note= NC3; | 
| PavelM | 1:970adc6aae96 | 94 | |
| PavelM | 1:970adc6aae96 | 95 | midi.write(MIDIMessage::NoteOn(note)); | 
| PavelM | 1:970adc6aae96 | 96 | wait(0.1); | 
| PavelM | 1:970adc6aae96 | 97 | |
| PavelM | 0:8e6b0e518883 | 98 | } | 
| PavelM | 1:970adc6aae96 | 99 | } | 
