|
/********************************************************************************************* |
|
MIDI OUT DEMO |
|
|
|
Ce sketch permet à l'Arduino de jouer une mélodie sur un clavier MIDI. |
|
|
|
Plus d'infos: |
|
|
|
http://electroniqueamateur.blogspot.com/2011/07/communication-midi-avec-un-arduino.html |
|
|
|
**********************************************************************************************/ |
|
|
|
/* On définit quelques notes qu'on va utiliser: ce sera plus pratique que les valeurs hexadécimales! |
|
Voir http://www.wavosaur.com/download/midi-note-hex.php */ |
|
|
|
#define NOTE_G2 0x2B |
|
#define NOTE_C3 0x30 |
|
#define NOTE_C4 0x3C |
|
#define NOTE_D4 0x3E |
|
#define NOTE_E4 0x40 |
|
#define NOTE_F4 0x41 |
|
#define NOTE_G4 0x43 |
|
#define NOTE_A4 0x45 |
|
#define NOTE_B4 0x47 |
|
#define NOTE_C5 0x48 |
|
#define NOTE_D5 0x4A |
|
#define NOTE_E5 0x4C |
|
#define NOTE_F5 0x4D |
|
#define NOTE_G5 0x4F |
|
#define NOTE_A5 0x51 |
|
#define NOTE_B5 0x53 |
|
|
|
// appelé pour jouer une note |
|
void noteOn(int cmd, int pitch, int velocity) { |
|
Serial.write(cmd); |
|
Serial.write(pitch); |
|
Serial.write(velocity); |
|
} |
|
|
|
// appelé pour modifier le timbre de l'instrument |
|
void ProgChange(int channel, int prognumber) { |
|
Serial.write(0xC0 + channel); |
|
Serial.write(prognumber); |
|
} |
|
|
|
void setup() { |
|
Serial.begin(31250); // réglage du baud rate à la norme MIDI |
|
} |
|
|
|
void loop() { |
|
|
|
// préparation des instruments: |
|
ProgChange(0, 34); // Bass guitar sur le canal 0 |
|
ProgChange(1, 16); // orgue sur le canal 1 |
|
ProgChange(2, 80); // synthé sur le canal 2 |
|
// le canal 9 joue toujours des percussions |
|
|
|
// on joue une courte mélodie: |
|
|
|
noteOn(0x99, 42, 0x45); // Closed Hi-Hat |
|
noteOn(0x99, 36, 0x45); // Bass Drum |
|
noteOn(0x90, NOTE_C3, 0x45); // Basse |
|
noteOn(0x92, NOTE_E5, 0x50); // Synthé |
|
delay(200); |
|
noteOn(0x99, 42, 0x00); // Closed Hi-Hat fin |
|
noteOn(0x99, 36, 0x00); // Bass Drum fin |
|
noteOn(0x92, NOTE_E5, 0x00); // Synthé fin |
|
|
|
noteOn(0x99, 42, 0x45); // Closed Hi-Hat |
|
noteOn(0x92, NOTE_D5, 0x50); // Synthé |
|
delay(200); |
|
noteOn(0x99, 42, 0x00); // Closed Hi-Hat fin |
|
noteOn(0x90, NOTE_C3, 0x00); // Basse fin |
|
noteOn(0x92, NOTE_D5, 0x00); // Synthé fin |
|
|
|
noteOn(0x99, 42, 0x45); // Closed Hi-Hat |
|
noteOn(0x99, 38, 0x45); // Bass Drum |
|
noteOn(0x91, NOTE_C4, 0x65); // orgue |
|
noteOn(0x91, NOTE_E4, 0x65); // orgue |
|
noteOn(0x91, NOTE_G4, 0x65); // orgue |
|
delay(200); |
|
noteOn(0x99, 42, 0x00); // Closed Hi-Hat fin |
|
noteOn(0x99, 38, 0x00); // Bass Drum fin |
|
|
|
noteOn(0x99, 42, 0x45); // Closed Hi-Hat |
|
delay(200); |
|
noteOn(0x99, 42, 0x00); // Closed Hi-Hat fin |
|
noteOn(0x91, NOTE_C4, 0x00); // orgue fin |
|
noteOn(0x91, NOTE_E4, 0x00); // orgue fin |
|
noteOn(0x91, NOTE_G4, 0x00); // orgue fin |
|
|
|
noteOn(0x99, 42, 0x45); // Closed Hi-Hat |
|
noteOn(0x99, 36, 0x45); // Bass Drum |
|
noteOn(0x90, NOTE_G2, 0x45); // Basse |
|
noteOn(0x92, NOTE_G5, 0x50); // Synthé |
|
delay(200); |
|
noteOn(0x99, 42, 0x00); // Closed Hi-Hat fin |
|
noteOn(0x99, 36, 0x00); // Bass Drum fin |
|
noteOn(0x92, NOTE_G5, 0x00); // Synthé fin |
|
|
|
noteOn(0x99, 42, 0x45); // Closed Hi-Hat |
|
noteOn(0x92, NOTE_E5, 0x50); // Synthé |
|
delay(200); |
|
noteOn(0x99, 42, 0x00); // Closed Hi-Hat fin |
|
noteOn(0x90, NOTE_G2, 0x00); // Basse fin |
|
noteOn(0x92, NOTE_E5, 0x00); // Synthé fin |
|
|
|
noteOn(0x99, 42, 0x45); // Closed Hi-Hat |
|
noteOn(0x99, 38, 0x45); // Bass drum |
|
noteOn(0x91, NOTE_C4, 0x65); // orgue |
|
noteOn(0x91, NOTE_E4, 0x65); // orgue |
|
noteOn(0x91, NOTE_G4, 0x65); // orgue |
|
delay(200); |
|
noteOn(0x99, 42, 0x00); // Closed Hi-Hat fin |
|
noteOn(0x99, 38, 0x00); // Bass drum fin |
|
|
|
noteOn(0x99, 42, 0x45); // Closed Hi-Hat |
|
delay(200); |
|
noteOn(0x99, 42, 0x00); // Closed Hi-Hat fin |
|
noteOn(0x91, NOTE_C4, 0x00); // orgue fin |
|
noteOn(0x91, NOTE_E4, 0x00); // orgue fin |
|
noteOn(0x91, NOTE_G4, 0x00); // orgue fin |
|
|
|
} |