Errata for Page 310:

<-back to errata for Physical Computing.

I know I should start with the stuff I will be working with next week in class but I just got back from giving a talk on using sysex to debug arduino code over midi. http://www.suspectdevices.com/talks/EpicMidiFail/assets/fallback/index.html  So my head is in the midi domain.

The pseudo code is

loop:
    read sensor
    convert sensor value to a note
    play MIDI note
    pause a quarter second
    stop MIDI note
end loop

There are two ways to send the midi note on/off message.

1. You can write the (3) bytes out at 31250 baud.

p310midi-no-library.ino

 

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.
}

Or you can use the GPL3d midi library provided by the arduino.

p310midi-gpl3-library.ino

#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); 
}

Leave a Reply

  • (will not be published)