cours 1

Dependencies:   mbed USBDevice

Committer:
samux
Date:
Fri Nov 04 11:44:41 2011 +0000
Revision:
0:7145560b8847
Child:
1:4108aa07d2a7

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
samux 0:7145560b8847 1 // Hello World example for the USBMIDI library
samux 0:7145560b8847 2
samux 0:7145560b8847 3 #include "mbed.h"
samux 0:7145560b8847 4 #include "USBMIDI.h"
samux 0:7145560b8847 5
samux 0:7145560b8847 6 USBMIDI midi;
samux 0:7145560b8847 7
samux 0:7145560b8847 8 //Bus of buttons
samux 0:7145560b8847 9 BusInOut buttons(p21, p22, p23, p24, p25, p26, p29);
samux 0:7145560b8847 10
samux 0:7145560b8847 11 int main() {
samux 0:7145560b8847 12 uint8_t p_bus = 0;
samux 0:7145560b8847 13 uint8_t bus = 0;
samux 0:7145560b8847 14 uint8_t add;
samux 0:7145560b8847 15 while (1) {
samux 0:7145560b8847 16 //if buttons state change, send a MIDI message
samux 0:7145560b8847 17 bus = buttons.read();
samux 0:7145560b8847 18 if (bus != p_bus) {
samux 0:7145560b8847 19 p_bus = bus;
samux 0:7145560b8847 20 if (p_bus) {
samux 0:7145560b8847 21 for (int i = 0; i < 7; i++) {
samux 0:7145560b8847 22 add = (p_bus & (1 << i)) ? (i + 1) : 0;
samux 0:7145560b8847 23 if (add) {
samux 0:7145560b8847 24 midi.write(MIDIMessage::NoteOn(48 + add));
samux 0:7145560b8847 25 midi.write(MIDIMessage::NoteOff(48 + add));
samux 0:7145560b8847 26 }
samux 0:7145560b8847 27 }
samux 0:7145560b8847 28 }
samux 0:7145560b8847 29 }
samux 0:7145560b8847 30 wait(0.001);
samux 0:7145560b8847 31 }
samux 0:7145560b8847 32 }