From c8c4f567bee435ef141e0fbb21158a04ba231206 Mon Sep 17 00:00:00 2001 From: Francois Best Date: Tue, 22 May 2012 21:50:54 +0200 Subject: [PATCH] Added Teensy examples. --- .../Teensy_MIDI_Blink/Teensy_MIDI_Blink.pde | 20 +++++++++++ .../Teensy_MIDI_Callbacks.pde | 31 ++++++++++++++++ .../Teensy_MIDI_Debug/Teensy_MIDI_Debug.pde | 23 ++++++++++++ .../Teensy_USB_MIDI_Callbacks.pde | 35 +++++++++++++++++++ 4 files changed, 109 insertions(+) create mode 100644 res/Examples/Teensy_MIDI_Blink/Teensy_MIDI_Blink.pde create mode 100644 res/Examples/Teensy_MIDI_Callbacks/Teensy_MIDI_Callbacks.pde create mode 100644 res/Examples/Teensy_MIDI_Debug/Teensy_MIDI_Debug.pde create mode 100644 res/Examples/Teensy_USB_MIDI_Callbacks/Teensy_USB_MIDI_Callbacks.pde diff --git a/res/Examples/Teensy_MIDI_Blink/Teensy_MIDI_Blink.pde b/res/Examples/Teensy_MIDI_Blink/Teensy_MIDI_Blink.pde new file mode 100644 index 0000000..7722765 --- /dev/null +++ b/res/Examples/Teensy_MIDI_Blink/Teensy_MIDI_Blink.pde @@ -0,0 +1,20 @@ +#include + +const int ledPin = 11; // Teensy has LED on 11, Teensy++ on 6 + +void setup() { + MIDI.begin(); + pinMode(ledPin,OUTPUT); +} + +void loop() { + if (MIDI.read()) { + digitalWrite(ledPin, HIGH); // set the LED on + delay(50); // wait for a second + digitalWrite(ledPin, LOW); // set the LED off + //delay(100); // wait for a second + } +} + + + diff --git a/res/Examples/Teensy_MIDI_Callbacks/Teensy_MIDI_Callbacks.pde b/res/Examples/Teensy_MIDI_Callbacks/Teensy_MIDI_Callbacks.pde new file mode 100644 index 0000000..50fc5b2 --- /dev/null +++ b/res/Examples/Teensy_MIDI_Callbacks/Teensy_MIDI_Callbacks.pde @@ -0,0 +1,31 @@ +#include + +const int ledPin = 11; // Teensy has LED on 11, Teensy++ on 6 + +// NoteOn Callback (will be called upon reception of a NoteOn message +void TurnLedOn(byte inChannel,byte inNote,byte inVelocity) { + if (inVelocity == 0) { + // NoteOn + null velo = note off. + digitalWrite(ledPin,LOW); + } + else digitalWrite(ledPin,HIGH); +} + +// NoteOff Callback (will be called upon reception of a NoteOff message +void TurnLedOff(byte inChannel,byte inNote,byte inVelocity) { + digitalWrite(ledPin,LOW); +} + +void setup() { + pinMode(ledPin,OUTPUT); + MIDI.begin(); + MIDI.setHandleNoteOn(TurnLedOn); // Connect callback for NoteOn + MIDI.setHandleNoteOff(TurnLedOff); // Connect callback for NoteOff +} + +void loop() { + MIDI.read(); // Keep reading MIDI input +} + + + diff --git a/res/Examples/Teensy_MIDI_Debug/Teensy_MIDI_Debug.pde b/res/Examples/Teensy_MIDI_Debug/Teensy_MIDI_Debug.pde new file mode 100644 index 0000000..785f33d --- /dev/null +++ b/res/Examples/Teensy_MIDI_Debug/Teensy_MIDI_Debug.pde @@ -0,0 +1,23 @@ +#include + +const int ledPin = 11; // Teensy has LED on 11, Teensy++ on 6 + +void Callback(word data) { + digitalWrite(ledPin,HIGH); + delay(100); + digitalWrite(ledPin,LOW); + delay(100); +} + +void setup() { + pinMode(ledPin,OUTPUT); + MIDI.begin(); // Start MIDI on DIN plugs + MIDI.setHandleSongPosition(Callback); +} + +void loop() { + MIDI.read(); +} + + + diff --git a/res/Examples/Teensy_USB_MIDI_Callbacks/Teensy_USB_MIDI_Callbacks.pde b/res/Examples/Teensy_USB_MIDI_Callbacks/Teensy_USB_MIDI_Callbacks.pde new file mode 100644 index 0000000..f1672c9 --- /dev/null +++ b/res/Examples/Teensy_USB_MIDI_Callbacks/Teensy_USB_MIDI_Callbacks.pde @@ -0,0 +1,35 @@ +#include + +const int ledPin = 11; // Teensy has LED on 11, Teensy++ on 6 + +// NoteOn Callback (will be called upon reception of a NoteOn message +void TurnLedOn(byte inChannel,byte inNote,byte inVelocity) { + if (inVelocity == 0) { + // NoteOn + null velo = note off. + digitalWrite(ledPin,LOW); + } + else digitalWrite(ledPin,HIGH); +} + +// NoteOff Callback (will be called upon reception of a NoteOff message +void TurnLedOff(byte inChannel,byte inNote,byte inVelocity) { + digitalWrite(ledPin,LOW); +} + +void setup() { + pinMode(ledPin,OUTPUT); + MIDI.begin(); + usbMIDI.begin(); + usbMIDI.setHandleNoteOn(TurnLedOn); // Connect callback for NoteOn + MIDI.setHandleNoteOn(TurnLedOn); // Connect callback for NoteOn + usbMIDI.setHandleNoteOff(TurnLedOff); // Connect callback for NoteOff + MIDI.setHandleNoteOff(TurnLedOff); // Connect callback for NoteOff +} + +void loop() { + MIDI.read(); // Keep reading MIDI input + usbMIDI.read(); +} + + +