Page 310: Advanced Methods (midi)

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.  So my head is in the midi domain.

The pseudo code is

    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.



int sensor = 2;
void setup()
 // Set MIDI baud rate:

void loop()
 int value=analogRead(sensor);
 int note = map(value, 1, 750/65, 60, 71);
 Serial.write(0x90); //note on channel 1
 Serial.write(0x45); //velocity.
 Serial.write(0x90); //note on channel 1
 Serial.write(0x00); //velocity=0->OFF.

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


#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); 
  delay(250); // Wait for a bit

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.