
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();
}
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;
#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.

Hi
ReplyDeleteI am trying to get data coming from a Ping ))) ultrasonic sensor plugged into an arduino to control midi parameters on my mac - but so far no luck. I tried the code provided on the little-scale blog but it does not seem to work. Have you managed to find a working method for getting data from the Ping sensor into MIDI?
any help would be greatly appreciated
Washing machine service in dubai
ReplyDeletehttps://www.hometech.ae/service/washing-machine-service/
UAEs Authorized Major brand Washing Machine Service in Dubai, On-Demand experienced professionals for washing machine service in Dubai.
1633341747346-11