You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To use this script, first flash the Mbed board with the code above. Connect the target's USB to the host computer. Then run this script. The script will send 8 bytes of data (1 2 3 4 5 6 7 8) to the Mbed board and will read and print the data sent to the host computer by the Mbed board.
62
20
63
-
```Py
64
-
from pywinusb import hid
65
-
66
-
# Whenever the host computer receives data from the
67
-
# Mbed board, the received data is printed
68
-
def on_data(data):
69
-
print(f"Got message {data}")
70
-
71
-
'''
72
-
Gets all HIDs currently connected to host computer,
73
-
and sets the first device with string "mbed" in its
74
-
vendor name equal to variable mbed. This variable
75
-
will be used to send data to the Mbed board.
76
-
'''
77
-
all_hid_devices = hid.find_all_hid_devices()
78
-
mbed_devices = [d for d in all_hid_devices if "mbed" in d.vendor_name]
You can use USBMIDI to play an entire song, not just a series of notes. "Take Me Out to the Ball Game" is a popular song in the public domain. To play "Take Me Out to the Ball Game" (public domain) using MIDI over USB on the host PC:
46
30
47
-
```C++ TODO
48
-
#include"mbed.h"
49
-
#include"USBMIDI.h"
50
-
51
-
#defineREST -1
52
-
#define C 0
53
-
#define Cs 1
54
-
#define D 2
55
-
#define Ds 3
56
-
#define E 4
57
-
#define F 5
58
-
#define Fs 6
59
-
#define G 7
60
-
#define Gs 8
61
-
#define A 9
62
-
#define As 10
63
-
#define B 11
64
-
65
-
#defineOCTAVE0 0
66
-
#define OCTAVE1 12
67
-
#define OCTAVE2 24
68
-
#define OCTAVE3 36
69
-
#define OCTAVE4 48
70
-
#define OCTAVE5 60
71
-
#define OCTAVE6 72
72
-
#define OCTAVE7 84
73
-
74
-
#defineWHOLE_NOTE 1.15
75
-
#defineHALF_NOTE (WHOLE_NOTE / 2)
76
-
#defineQUARTER_NOTE (WHOLE_NOTE / 4)
77
-
#define EIGHTH_NOTE (WHOLE_NOTE / 8)
78
-
#define SIXTEENTH_NOTE (WHOLE_NOTE / 16)
79
-
80
-
#defineTHREE_EIGHTHS_NOTE (EIGHTH_NOTE * 3)
81
-
#define THREE_FORTHS_NOTE (QUARTER_NOTE * 3)
82
-
83
-
USBMIDI midi;
84
-
85
-
voidPlayNote(int note, int octave, float duration){
0 commit comments