MIDI-------

using the MIDI out (hopefully done with Max msp) function, by using a switch (the comb) to say when (when comb) to send the midi

(thanks ryan).

to be used with arduino board.


/* a simple MIDI out
sends a MIDI message when a switch on pin 13 is activated
MIDI is sent from TX pin 1 on Aurduino board
note on channel 1, key 69, velocity 127

*/

int LEDpin = 13;
int SwitchPin = 10;

int i = 0;
int blast = 0;
void blink();
void midiOut(char cmd, char data1, char data2);

void setup() {
pinMode(LEDpin, OUTPUT);
pinMode(SwitchPin, INPUT);

beginSerial(31250); //sets the MIDI baud rate
blink();
}

void loop() {
if (digitalRead(SwitchPin) == 1) {
digitalWrite(LEDpin, HIGH);
for (blast =0;blast< 1;blast++) {
midiOut (0x90, 0x45,0x7F); // numbers in c style Hex (note on,
key, velocity)
// wait 10ms for next reading:
delay(10);
midiOut (0x90,0x45,0); // turns the note off
delay (10);
}
}
else {
digitalWrite(LEDpin, LOW);
}
}

// Blinks an LED 3 times
void blink() {
for (i=0; i<2; i++) {
digitalWrite(LEDpin, HIGH);
delay(100);
digitalWrite(LEDpin, LOW);
delay(100);
}
}

void midiOut(char cmd, char data1, char data2) {
serialWrite(cmd);
serialWrite(data1);
serialWrite(data2);
}

 

OR THIS OTHER ONE-----(tom igoe)

(still, the 3 sensors part it might not be the thing i'm looking for------/////?)

Serial Call-and-Response (Arduino/Wiring)

This code for Arduino or Wiring reads three sensors and sends them out serially when prompted by another computer. It works with this Processing example.

/*
analog Call-and-Response
by Tom Igoe

Waits for serial input. If the incoming value
is a valid byte (i.e. 0 - 255), the program then
reads two analog inputs and one digital input.
It divides the anaog inputs by 4
to convert the ranges to 0 = 255, and
sends all three sensor values out serially.

Arduino hardware connections:
A0: potentiometer on analog in 1
A1: potentiometer on analog in 2
D2: switch on digital in 2

Created 26 Sept. 2005
Updated 30 May 2006
*/

int firstSensor = 0; // first analog sensor
int secondSensor = 0; // second analog sensor
int thirdSensor = 0; // digital sensor
int inByte = 0; // incoming serial byte

void setup()
{
// start serial port at 9600 bps:
Serial.begin(9600);
}

void loop()
{
// if we get a valid byte, read analog ins:
if (Serial.available() > 0) {
// get incoming byte:
inByte = Serial.read();
// read first analog input, divide by 4 to make the range 0-255:
firstSensor = analogRead(0)/4;
// delay 10ms to let the ADC recover:
delay(10);
// read second analog input, divide by 4 to make the range 0-255:
secondSensor = analogRead(1)/4;
// read switch, multiply by 255
// so that you're sending 0 or 255:
thirdSensor = 255 * digitalRead(2);
// send sensor values:
Serial.print(firstSensor, BYTE);
Serial.print(secondSensor, BYTE);
Serial.print(thirdSensor, BYTE);
}
}