| 1 | // ***************************************************************************************************************** |
| 2 | // * * |
| 3 | // * SpikenzieLabs.com * |
| 4 | // * * |
| 5 | // * Very Simple Serial to MIDI DEMO * |
| 6 | // * * |
| 7 | // ***************************************************************************************************************** |
| 8 | // |
| 9 | // BY: MARK DEMERS |
| 10 | // May 2009 |
| 11 | // VERSION: 0.1 |
| 12 | // |
| 13 | // DESCRIPTION: |
| 14 | // Demo sketch to play notes from middle C in the 4th octave up to B in the 5th octave and then back down. |
| 15 | // |
| 16 | // |
| 17 | // HOOK-UP: |
| 18 | // 1. Plug USB cable from Arduino into your computer. |
| 19 | // |
| 20 | // |
| 21 | // USAGE: |
| 22 | // 1. Install and Set-up Serial MIDI Converter from SpikenzieLabs |
| 23 | // 2. Open, compile, and upload this sketch into your Arduino. |
| 24 | // 3. Run Serial MIDI Converter in the background. |
| 25 | // 4. Launch your music software such as Garage Band or Ableton Live, choose a software instrument and listen to the music. |
| 26 | // |
| 27 | // |
| 28 | // LEGAL: |
| 29 | // This code is provided as is. No guaranties or warranties are given in any form. It is up to you to determine |
| 30 | // this codes suitability for your application. |
| 31 | // |
| 32 | |
| 33 | int note = 0; |
| 34 | |
| 35 | void setup() |
| 36 | { |
| 37 | Serial.begin(57600); // Default speed of the Serial to MIDI Converter serial port |
| 38 | } |
| 39 | |
| 40 | void loop() |
| 41 | { |
| 42 | |
| 43 | for(int note=60; note<=83; note++) // Going Up |
| 44 | { |
| 45 | MIDI_TX(144,note,127); // NOTE ON |
| 46 | delay(100); |
| 47 | |
| 48 | MIDI_TX(128,note,127); // NOTE OFF |
| 49 | delay(100); |
| 50 | } |
| 51 | |
| 52 | for(int note=82; note>=61; note--) // Coming Down |
| 53 | { |
| 54 | MIDI_TX(144,note,127); // NOTE ON |
| 55 | delay(250); |
| 56 | |
| 57 | MIDI_TX(128,note,127); // NOTE OFF |
| 58 | delay(250); |
| 59 | } |
| 60 | |
| 61 | } |
| 62 | |
| 63 | |
| 64 | void MIDI_TX(unsigned char MESSAGE, unsigned char PITCH, unsigned char VELOCITY) |
| 65 | { |
| 66 | Serial.print(MESSAGE); |
| 67 | Serial.print(PITCH); |
| 68 | Serial.print(VELOCITY); |
| 69 | } |
| 70 | |
| 71 | |