Daniel? you may be fed up with my lameness by now but if you so happen to be looking to this thread at all do you (or anyone else) have any idea why this code would produce nothing in max?
/*
* Arduino2Max w/ 4051
* Send pin values from Arduino to MAX/MSP
*
* Arduino2Max.pde
* ------------
* Latest update: September 2007
* ------------
* Copyleft: use as you like
* by djmatic
* Based on a sketch and patch by Thomas Ouellet Fredericks tof.danslchamp.org
*
*/
int x = 0; // a place to hold pin values
int bin [] = {000, 1, 10, 11, 100, 101, 110, 111}; //bin = binär, some times it is so easy
int r0 = 0; //value select pin at the 4051 (s0)
int r1 = 0; //value select pin at the 4051 (s1)
int r2 = 0; //value select pin at the 4051 (s2)
int row = 0; // storeing the bin code
int count = 0; // just a count
int analogPin = 0;
int threshold = 25; // threshold
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);
pinMode(2, OUTPUT); // s0
pinMode(3, OUTPUT); // s1
pinMode(4, OUTPUT); // s2
}
void loop()
{
if (Serial.available() > 0){ // Check serial buffer for characters
if (Serial.read() == 'r') { // If an 'r' is received then read the pins
// your code goes here. This is where you would prep the data
// by reading it with the 4051 etc.
for (count=0; count<=7; count++) {
row = bin[count];
r0 = row & 0x01;
r1 = (row>>1) & 0x01;
r2 = (row>>2) & 0x01;
digitalWrite(2, r0);
digitalWrite(3, r1);
digitalWrite(4, r2);
//Serial.println(bin[count]);
delay (5);
}
x = analogRead(analogPin);
sendValue (x); // this is the statement to send data to Max
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);
}