I need to upload code for an Uno that is using 6 digital (jack inputs) and 4 analog (jack inputs) to send controller information to Max.
The code that worked years ago seems to be outdated.
Could someone help me with this?
/*
- Arduino2Max
- Send pin values from Arduino to MAX/MSP
- Arduino2Max.pde
-
- This version: .4, October 2007
-
*/
//#incude <SimpleMessageSystem.h>
int x = 0; // a place to hold pin values
int ledpin = 13;
int abuttonPin = 2; // button 1
int bbuttonPin = 3; // button 2
int cbuttonPin = 4; // button 3
int dbuttonPin = 5; // button 4
int ebuttonPin = 6; // button 5
int fbuttonPin = 7; // button 6
int gbuttonPin = 8; // button 7
int hbuttonPin = 9; // button 8
int ibuttonPin = 10; // button 9
int jbuttonPin = 11; // button 10
int kbuttonPin = 12; // button 11
int lbuttonPin = 13; // button 12
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(abuttonPin, INPUT); // set pin2 to input
digitalWrite(abuttonPin, HIGH); // turn on pullup resistors
pinMode(bbuttonPin, INPUT); // set pin3 to input
digitalWrite(bbuttonPin, HIGH); // turn on pullup resistors
pinMode(cbuttonPin, INPUT); // set pin4 to input
digitalWrite(cbuttonPin, HIGH); // turn on pullup resistors
pinMode(dbuttonPin, INPUT); // set pin5 to input
digitalWrite(dbuttonPin, HIGH); // turn on pullup resistors
pinMode(ebuttonPin, INPUT); // set pin6 to input
digitalWrite(ebuttonPin, HIGH); // turn on pullup resistors
pinMode(fbuttonPin, INPUT); // set pin7 to input
digitalWrite(fbuttonPin, HIGH); // turn on pullup resistors
pinMode(gbuttonPin, INPUT); // set pin8 to input
digitalWrite(gbuttonPin, HIGH); // turn on pullup resistors
pinMode(hbuttonPin, INPUT); // set pin9 to input
digitalWrite(hbuttonPin, HIGH); // turn on pullup resistors
pinMode(ibuttonPin, INPUT); // set pin10 to input
digitalWrite(ibuttonPin, HIGH); // turn on pullup resistors
pinMode(jbuttonPin, INPUT); // set pin11 to input
digitalWrite(jbuttonPin, HIGH); // turn on pullup resistors
pinMode(kbuttonPin, INPUT); // set pin12 to input
digitalWrite(kbuttonPin, HIGH); // turn on pullup resistors
pinMode(lbuttonPin, INPUT); // set pin13 to input
digitalWrite(lbuttonPin, HIGH); // turn on pullup resistors
}
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.write(32);
}