0

I am using arduino uno, 2 multiplexer and voltage devider network in my circuit. I am using 8:1 analog multiplexer. Here is my below code. Problem i wanted to read the values when i send so,s1,s2,s3. Currently in below program i am just enabling the so,s1,s2 pins and reading the values. Once switching take place i wanted to read the values. For example when it read A0,A5 s0,s1,s2 are LOW. after 1s it tuns S0=0,S1=0,S1=1. Now the old data replaced by New analog values i.e with A1 from mux1 and A1 from Mux 2.

Datasheet attached here Here A0-A7 are connected via voltage devider network. to 2 multiplexer. S0,s1,s2,E are shorted for 2 muliplexer and given to 7,6,5,4 pins of arduino analog output read according with truth table.and controlled accordance with truth table.

Here in my code i can read analog values properly. But How can i store them or differentiate the Ao,A1 of mulitplexer outputs??? It should affect other channels.

 int SO_enable=7;
 int S1_enable=6;
 int S2_enable=5;
 int Enablepin=4;
 int Sensor_Value0=0;
 int Sensor_Value1=0;
float  voltage0;
float voltage1;
float ARDUINO_ANALOG_SCALING=0.0048875855327468231;
int row,column;

int array[9][4]={
                    {0,0,0,0},
                    {0,0,0,1},
                    {0,0,1,0},  
                    {0,0,1,1},
                    {0,1,0,0},
                    {0,1,0,1},
                    {0,1,1,0},
                    {0,1,1,1},
                    {1,0,0,0}

                 };




void setup()
{
  pinMode(SO_enable, OUTPUT) ;
   pinMode(S1_enable, OUTPUT) ;
   pinMode(S2_enable, OUTPUT) ;
    pinMode(Enablepin, OUTPUT) ;
     pinMode(A0, INPUT) ;
      pinMode(A5, INPUT) ;

   Serial.begin(9600);
}

void loop()
{
   for(row=0;row<9;row++)
  {
    int k=(8*array[row][0]+4*array[row][1]+2*array[row][2]+1*array[row][3]);
    Serial.print("value of k :");
    Serial.println(k);
      digitalWrite(Enablepin,array[row][0]);
      digitalWrite(SO_enable,array[row][1]);
      digitalWrite(S1_enable,array[row][2]);
      digitalWrite(S2_enable,array[row][3]);  

      Sensor_Value0=analogRead(A0);
      Sensor_Value1=analogRead(A5);
      voltage0=Sensor_Value0 * ARDUINO_ANALOG_SCALING;
      voltage1=Sensor_Value1* ARDUINO_ANALOG_SCALING;

        Serial.print("VOlt across Analog pin0:");
    Serial.println(voltage0);

    Serial.print("VOlt across Analog pin5:");
    Serial.println(voltage1);
    Serial.println("......................");
    delay(2000);

  }




}
4

1 回答 1

0

You want to get the voltage change over time? Why to just declare a global array like:

float prev_voltage0[9];
float prev_voltage1[9];

for (...) {
    ....
    //difference is (voltage0 - prev_voltage0[row])
    prev_voltage0[row] = voltage0;
    prev_voltage1[row] = voltage1;
    delay(2000);
}
于 2014-10-25T06:48:54.300 回答