diff options
| author | Donald Delmar Davis <don@suspectdevices.com> | 2013-02-02 15:50:25 -0800 |
|---|---|---|
| committer | Donald Delmar Davis <don@suspectdevices.com> | 2013-02-02 15:50:25 -0800 |
| commit | 46049bf57bdff5e3e564d60a0cc83e386a1b42f4 (patch) | |
| tree | 8c711585f5dd564be94bff62592f265796209f31 | |
| parent | bb94e4fd595235107ee4ff8a9e9a82d12a510705 (diff) | |
Midi code samples for chapter 12
| -rw-r--r-- | physical computing code fragments/p310midi-gpl3-library.ino | 28 | ||||
| -rw-r--r-- | physical computing code fragments/p310midi-no-library.ino | 34 |
2 files changed, 62 insertions, 0 deletions
diff --git a/physical computing code fragments/p310midi-gpl3-library.ino b/physical computing code fragments/p310midi-gpl3-library.ino new file mode 100644 index 0000000..d4c746c --- /dev/null +++ b/physical computing code fragments/p310midi-gpl3-library.ino @@ -0,0 +1,28 @@ +/* Page 310 Advanced Methods -- Midi + +Pseudocode: + +loop: + read sensor + convert sensor value to a note + play MIDI note + pause a quarter second + stop MIDI note +end loop + +This sample uses the arduino midi library midi data. + +*/ + +#include <Midi.h> +void setup() { + MIDI.begin(0); // input channel is set to 0 +} + +void loop() { + int value=analogRead(sensor); + note = map(value, 1, 750/65, 60, 71); + MIDI.sendNoteOn(note,40,0); + delay(250); // Wait for a bit + MIDI.sendNoteOff(note,0,0); +}
\ No newline at end of file diff --git a/physical computing code fragments/p310midi-no-library.ino b/physical computing code fragments/p310midi-no-library.ino new file mode 100644 index 0000000..2ece833 --- /dev/null +++ b/physical computing code fragments/p310midi-no-library.ino @@ -0,0 +1,34 @@ +/* Page 310 Advanced Methods -- Midi + +Pseudocode: + +loop: + read sensor + convert sensor value to a note + play MIDI note + pause a quarter second + stop MIDI note +end loop + +This sample uses print statements to send midi data. + +*/ + +int sensor = 2; +void setup() +{ + // Set MIDI baud rate: + Serial.begin(31250); +} + +void loop() + int value=analogRead(sensor); + int note = map(value, 1, 750/65, 60, 71); + Serial.write(0x90); //note on channel 1 + Serial.write(note); + Serial.write(0x45); //velocity. + delay(250); + Serial.write(0x90); //note on channel 1 + Serial.write(note); + Serial.write(0x00); //velocity=0->OFF. +}
\ No newline at end of file |
