Go Down

Topic: Mux Shield Analog In/Digital Out (Read 1 time) previous topic - next topic

Grumpy_Mike

OK try this. I have changed the logic so that if there is data it empties the buffer and then uses the last received readings to set the outputs. The way you had it was that the outputs were being set every time through the loop whether new data was received or not.

Code: [Select]
//Attempting mux0 and mux1 analog in, and mux2 digital out
#define CONTROL0 5   
#define CONTROL1 4
#define CONTROL2 3
#define CONTROL3 2

int maxData;

int mux0array[16];
int mux1array[16];

int A=0;
int B=0;
int C=0;
int D=0;

void setup()
{
 
  Serial.begin(28800);

  pinMode(CONTROL0, OUTPUT);
  pinMode(CONTROL1, OUTPUT);
  pinMode(CONTROL2, OUTPUT);
  pinMode(CONTROL3, OUTPUT);
}
 

void loop() {
for (int i=0; i<16; i++)
  {

    digitalWrite(CONTROL0, (i&15)>>3);
    digitalWrite(CONTROL1, (i&7)>>2); 
    digitalWrite(CONTROL2, (i&3)>>1); 
    digitalWrite(CONTROL3, (i&1));     
   
    mux0array[i] = analogRead(0);
  }
  // now print out the array
      Serial.print("mux0array: ");
    for (int i=0; i<16; i++)
  {
    Serial.print(mux0array[i]);
    Serial.print("-");
  }
    Serial.println();

 
for (int i=0; i<16; i++)
  {
    digitalWrite(CONTROL0, (i&15)>>3);
    digitalWrite(CONTROL1, (i&7)>>2); 
    digitalWrite(CONTROL2, (i&3)>>1); 
    digitalWrite(CONTROL3, (i&1));     
    mux1array[i] = analogRead(1);
}
    Serial.print("mux1array: ");
    for (int i=0; i<16; i++)
  {
    Serial.print(mux1array[i]);
    Serial.print("-");
  }
    Serial.println();
 
   
  pinMode(16, OUTPUT);
  if(Serial.available() > 0) {
       while(Serial.available() > 0) {
       maxData = Serial.read();
        }
     if (maxData == 0)
    {
    A = 2;
    B = 2;
    C = 2;
    D = 2;
    }
    if (maxData == 1)
    {
    A = 0;
    B = 0;
    C = 0;
    D = 0;
    }
    if (maxData == 3)
    {
    A = 1;
    B = 0;
    C = 0;
    D = 0;
    }
     if (maxData == 5)
    {
    A = 0;
    B = 1;
    C = 0;
    D = 0;
    }
    if (maxData == 7)
    {
    A = 1;
    B = 1;
    C = 0;
    D = 0;
    } 
    digitalWrite(16, HIGH);
    for (int i=0; i<16; i++)
    digitalWrite(CONTROL0, (D)); //S3
    digitalWrite(CONTROL1, (C)); //S2
    digitalWrite(CONTROL2, (B)); //S1
    digitalWrite(CONTROL3, (A)); //S0
}
}

etk1

Thanks for the code.  I'm still having issues with it working together... In fact, twisting a potentiometer hooked into one of the analog muliplexers is actually causing the led's to blink at different intensities.  I'm wondering if this has something to do with the way the shield is constructed, as the analog in's all read in a voltage even is something is not connected to them, and it will vary depending on the voltage coming through an in with something connected to it.  But thanks for all your help though so far Grumpy Mike!

Grumpy_Mike

#7
Aug 03, 2011, 07:19 am Last Edit: Aug 03, 2011, 07:24 am by Grumpy_Mike Reason: 1
Quote
as the analog in's all read in a voltage even is something is not connected to them, and it will vary depending on the voltage coming through an in with something connected to it.


No that is normal and is to do with the sample an hold capacitor on the input of the A/D converter. It is the same on the internal multiplexer of the arduino.

Is this bit right?
Code: [Select]
if (maxData == 0)
   {
   A = 2;
   B = 2;
   C = 2;
   D = 2;
   }

all the other things set these variables to 1 or 0.

Also this line:-
   digitalWrite(16, HIGH);
This pin is never set to anything else so what is it supposed to do?

Finnola7John

I am new to this so can anybody help me in supplying a link to the shield?

Grumpy_Mike

Look in the first post for the link.

Go Up