hi iv'e only just started using arduinos and max msp in the last few months so am relatively new to programming, but I was just wondering if anyone could help me with something. Im working on a project where i want to use some sensors connected to an arduino which then send midi data to max msp. I have one code for the arduino that converts the data from the sensors to midi data (code one), and I have another code and patch that work together to connect the arduino to max msp (code 2), but I cant work out how to add the two codes together so I can send the midi data from my sensors into max.
If anyone could help me in any way that would be brillant, here are the two codes
Code 1
// by Tubedogg 12/2006; fabian at tubedogg.de
//This program reads up to 6 analog sensors / potentiometers ans converts the data to Midi-Controller messages
// define Switchpin:
#define switchPin 10
// define LED:
#define LEDpin 13
// Variables
// define variables for the controller data
int AnalogValue[6] = {0,0,0,0,0,0};
// define the "lastValue" variables
int lastAnalogValue[6] = {0,0,0,0,0,0};
// select the midi Controller Number for each input
int midiCCselect[6] = {1,2,3,4,5,6};
// select threshold for each analog input
int thresh[6] = {1,1,1,1,1,1};
// select number of desired analog inputs (max 6)
int input_no = 6;
void setup() {
// set the states of the I/O pins:
pinMode(switchPin, INPUT);
pinMode(LEDpin, OUTPUT);
// Set MIDI baud rate:
Serial.begin(31250);
}
// main program loop
void loop() {
for(int i=0;i<input_no;i++){
AnalogValue = (analogRead(i))/8; // read the value from the analog input and divide by 8 for range 0-127
- // check if value is greater than defined threshold (good for resistive touchpads etc)*
if ( AnalogValue >thresh ) {
* // check if analog input has changed*
if ( AnalogValue != lastAnalogValue ) {
* //send control change on cc#i*
midiCC(0xB0, midiCCselect_, AnalogValue*);
// update lastAnalogValue variable*
lastAnalogValue = AnalogValue*;*
* //End if*
* }
//End if*
* }*_
//End for
}
//End Loop
}
// This function sends a Midi CC.
void midiCC(char CC_data, char c_num, char c_val){
Serial.print(CC_data, BYTE);
Serial.print(c_num, BYTE);
Serial.print(c_val, BYTE);
}
Code 2 /*
* Arduino2Max
* Send pin values from Arduino to MAX/MSP
*
* Arduino2Max.pde
* ------------
* This version: .5, November 29, 2010
* ------------
* Copyleft: use as you like
* by Daniel Jolliffe
* Based on a sketch and patch by Thomas Ouellet Fredericks tof.danslchamp.org
*
*/
int x = 0; // a place to hold pin values
int ledpin = 13;
void setup()
{
* Serial.begin(115200); // 115200 is the default Arduino Bluetooth speed*
* digitalWrite(13,HIGH); ///startup blink*
* delay(600);*
* digitalWrite(13,LOW);*
* pinMode(13,INPUT);*
}
void loop()
{
if (Serial.available() > 0){ // Check serial buffer for characters
* if (Serial.read() == 'r') { // If an 'r' is received then read the pins*
for (int pin= 0; pin<=5; pin++){ // Read and send analog pins 0-5
* x = analogRead(pin);*
* sendValue (x);*
* }*
for (int pin= 2; pin<=13; pin++){ // Read and send digital pins 2-13
* x = digitalRead(pin);*
* sendValue (x);*
* }*
* Serial.println(); // Send a carriage returnt to mark end of pin data.*
* delay (5); // add a delay to prevent crashing/overloading of the serial port*
* }*
}
}
void sendValue (int x){ // function to send the pin value followed by a "space".
Serial.print(x);
Serial.print(32, BYTE);
}