/* * Arduino2Max * Send pin values from Arduino to MAX/MSP * * Arduino2Max.pde * ------------ * This version: .4, October 2007 * ------------ * Copyleft: use as you like * by Daniel Jolliffe * Based on a sketch and patch by Thomas Ouellet Fredericks tof.danslchamp.org * * Heavily edited for his own purposes by, Michael Berger (2008-9) */ int x = 0; 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); pinMode(2, OUTPUT); pinMode(3, OUTPUT); pinMode(4, OUTPUT); } void loop() { //if (Serial.available() > 0){ // Check serial buffer for characters // if (Serial.read() == 'r') { // If an 'r' is received then read the pins //************************************************** //ANALOG READ 0-2 for (int pin = 0; pin <= 2; pin++){ // Read and send analog pins 0-2 (accelerometer) x = analogRead(pin); sendValue (x); } //************************************************** //MULTIPLEXED ANALOG READ 3 //Hall Effect #1 (LHL) digitalWrite(2, LOW); digitalWrite(3, HIGH); digitalWrite(4, LOW); sendValue(analogRead(3)); //Hall Effect #2 (LHH) digitalWrite(4, HIGH); sendValue(analogRead(3)); //Hall Effect #3 (LLL) digitalWrite(3, LOW); digitalWrite(4, LOW); sendValue(analogRead(3)); //Hall Effect #4 (LLH) digitalWrite(4, HIGH); sendValue(analogRead(3)); //Hall Effect #5 (HLL) digitalWrite(2, HIGH); digitalWrite(4, LOW); sendValue(analogRead(3)); //Hall Effect #6 (HLH) digitalWrite(4, HIGH); sendValue(analogRead(3)); //************************************************** 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 // } // } } //************************************************** // FUNCTIONS //************************************************** void sendValue (int x){ // function to send the pin value followed by a "space". Serial.print(x); Serial.print(32, BYTE); }