SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By StealthRT
#184945
These are the values i get when i have USB LED 1 ON:
Code: Select all
    USB LED 1: 737
    USB LED 2: 711
    USB LED 1: 734
    USB LED 2: 710
    USB LED 1: 734
    USB LED 2: 710
    USB LED 1: 733
    USB LED 2: 709
    USB LED 1: 734
    USB LED 2: 709
    USB LED 1: 734
    USB LED 2: 710
These are the values I have with USB LED 1 OFF:
Code: Select all
    USB LED 1: 736
    USB LED 2: 720
    USB LED 1: 734
    USB LED 2: 720
    USB LED 1: 734
    USB LED 2: 719
    USB LED 1: 734
    USB LED 2: 719
    USB LED 1: 734
    USB LED 2: 720
    USB LED 1: 734
    USB LED 2: 719
    USB LED 1: 733
These are the values when USB LED 2 ON:
Code: Select all
    USB LED 1: 736
    USB LED 2: 719
    USB LED 1: 734
    USB LED 2: 719
    USB LED 1: 734
    USB LED 2: 720
    USB LED 1: 734
    USB LED 2: 720
    USB LED 1: 734
    USB LED 2: 718
And these are the values with USB LED 2 OFF:
Code: Select all
    USB LED 1: 737
    USB LED 2: 710
    USB LED 1: 734
    USB LED 2: 710
    USB LED 1: 734
    USB LED 2: 710
    USB LED 1: 735
    USB LED 2: 710
    USB LED 1: 735
    USB LED 2: 711
Are you can see above, its a very SLIM margin when the LED is either on or off.

When LED 1 is ON its : from 733 to 734

When LED 1 is OFF its: from 734 to 736

When LED 2 is ON its : from 718 to 720

When LED 2 is OFF its: from 710 to 711

What I am hoping to get is a constant number instead of a random range so that I know for sure its either ON or OFF. 734 ON and also 734 for OFF does not cut it for trying to figure out if its on or off.

Here is the Arduino code:
Code: Select all
    //Mux control pins
    int s0 = 8;
    int s1 = 9;
    int s2 = 10;
    int s3 = 11;
    
    //Mux in "SIG" pin
    int SIG_pin = 0;
        
    void setup(){
      pinMode(s0, OUTPUT); 
      pinMode(s1, OUTPUT); 
      pinMode(s2, OUTPUT); 
      pinMode(s3, OUTPUT); 
    
      digitalWrite(s0, LOW);
      digitalWrite(s1, LOW);
      digitalWrite(s2, LOW);
      digitalWrite(s3, LOW);
    
      Serial.begin(9600);
    }
        
    void loop(){
        int val = readMux(1);
        Serial.print("USB LED 1: ");
        Serial.println(val);
        delay(1000);
        
        val = readMux(0);
        Serial.print("USB LED 2: ");
        Serial.println(val);
        delay(1000);
    }
        
    int readMux(int channel){
      int controlPin[] = {s0, s1, s2, s3};
    
      int muxChannel[16][4]={
        {0,0,0,0}, //channel 0
        {1,0,0,0}, //channel 1
        {0,1,0,0}, //channel 2
        {1,1,0,0}, //channel 3
        {0,0,1,0}, //channel 4
        {1,0,1,0}, //channel 5
        {0,1,1,0}, //channel 6
        {1,1,1,0}, //channel 7
        {0,0,0,1}, //channel 8
        {1,0,0,1}, //channel 9
        {0,1,0,1}, //channel 10
        {1,1,0,1}, //channel 11
        {0,0,1,1}, //channel 12
        {1,0,1,1}, //channel 13
        {0,1,1,1}, //channel 14
        {1,1,1,1}  //channel 15
      };
    
      //loop through the 4 sig
      for(int i = 0; i < 4; i ++){
        digitalWrite(controlPin[i], muxChannel[channel][i]);
      }
    
      //read the value at the SIG pin
      int val = analogRead(SIG_pin);
    
      //return the value
      return val;
    }
By n1ist
#184956
What is the mux connected to? What exactly are you trying to do?

Without much clue, I'd guess you are trying to tell if two LEDs are on or off, and have the mux tied to the wrong end of the LED...

/mike
By n1ist
#184994
Please give us a schematic; otherwise we are just guessing.

Take a DMM and check the voltages on the mux, both at the sides connecting to the LEDs and at the common pin. That will help figure out whether you are looking at a hardware or firmware issue.
/mike