Monday, 19 January 2009

putting it in a box


So this is the container for the arduino, it's my first attempt and building a usb interface and it didn't come out too badly. I need to screw the faders in as they are held in with tape, and get some nice knobs for it, but yeah it's just a nice little 2 channel thingy ma jig that sends midi data into live! (with an ultrasound sensor!)
Add Image

Saturday, 3 January 2009

8 pots to max/msp


Hi in this project I have been able to output the data from 8 pots through a 4051 to 1 pin on the arduino and unpack the data in max/msp.

Here's the working code for 8 pots and the max/msp patch to read it into separate boxes is below. 

int MuxPin1=2;
int MuxPin2=3;
int MuxPin3=4;
int AnaInPin1=4;

//Declare variables
int MuxVal1 = 0;
int MuxVal2 = 0;
int MuxVal3 = 0;
int BinVal = 0;
int N = 0;
byte data_send = 0;
byte data_in = 0;


//BinPat is used for figuring out the High / Low (1/0) values of the MUX control pins

int BinPat [] = {000, 1, 10, 11, 100, 101, 110, 111};


void setup()

{

//Initialize digital pins and serial communication speed

pinMode(MuxPin1, OUTPUT);

pinMode(MuxPin2, OUTPUT);

pinMode(MuxPin3, OUTPUT);

beginSerial(19200);

}


void loop() {


if(Serial.available() > 0) {
data_in = Serial.read();
if(data_in == 76) {
readPotValues();
}
}

delay (10);

}


void readPotValues()

{

for (N=0; N<=7; N++) { BinVal = BinPat[N]; MuxVal1 = BinVal & 0x01; MuxVal2 = (BinVal>>1) & 0x01;
MuxVal3 = (BinVal>>2) & 0x01;
digitalWrite(MuxPin1, MuxVal1);
digitalWrite(MuxPin2, MuxVal2);
digitalWrite(MuxPin3, MuxVal3);
data_send=analogRead(AnaInPin1) / 4;
Serial.print(data_send);
}
Serial.flush();

}


here's the max/msp patch this has not been tested on max 5:

(just copy the text and go open from clipboard in max)

#P window setfont "Sans Serif" 9.;
#P number 582 340 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 517 340 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 452 340 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 387 340 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 322 340 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 257 340 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 192 340 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 127 340 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 127 286 468 196617 unpack 1 2 3 4 5 6 7 8;
#P newex 127 240 52 196617 route list;
#P newex 80 170 57 196617 route read;
#P message 78 74 20 196617 76;
#P toggle 79 22 15 0;
#P newex 127 208 55 196617 zl group 8;
#P newex 80 144 77 196617 serial a 19200;
#P newex 79 53 52 196617 metro 10;
#P newex 42 119 43 196617 delay 4;
#P button 42 100 15 0;
#P connect 0 0 1 0;
#P connect 2 0 6 0;
#P connect 5 0 2 0;
#P fasten 6 0 3 0 83 120 85 120;
#P fasten 6 0 0 0 83 98 47 98;
#P fasten 1 0 3 0 47 139 85 139;
#P connect 3 0 7 0;
#P connect 7 1 4 0;
#P connect 4 0 8 0;
#P connect 8 0 9 0;
#P connect 9 0 10 0;
#P connect 9 1 11 0;
#P connect 9 2 12 0;
#P connect 9 3 13 0;
#P connect 9 4 14 0;
#P connect 9 5 15 0;
#P connect 9 6 16 0;
#P connect 9 7 17 0;
#P window clipboard copycount 18;

I am trying to get 16 to work the same way and will post the code as soon as it is finished. Hope this all helps.