Hi I've got a 4051 and 8 pots working and outputting numbers that i want to see in the serial monitor, but i don't know how to send the data into max/msp i think i need to get max to send a letter to arduino telling it to read the pots buut am getting confused with other peoples examples online because the code i have adapted is slightly different. here's what I got so far:
// adapted from post on this forum - more analog inputs
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;
//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};
//The PotValues array is used for storing the 16 vlues read from the potentiometers
int PotValues [] = {0,0,0,0,0,0,0,0};
void setup()
{
//Initialize digital pins and serial communication speed
pinMode(MuxPin1, OUTPUT);
pinMode(MuxPin2, OUTPUT);
pinMode(MuxPin3, OUTPUT);
beginSerial(19200);
}
void loop() {
readPotValues();
sendPotValues();
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);
PotValues[N]=analogRead(AnaInPin1);
}
}
void sendPotValues()
{
for (N=0; N<=6; N++)
{
Serial.print(PotValues[N]);
Serial.print(',');
}
Serial.println(PotValues[7]);
}
any help would be greatly appreciated
cheers and happy new year