Codigos Para Rabajar Con Multiles Salidas

download Codigos Para Rabajar Con Multiles Salidas

of 7

Transcript of Codigos Para Rabajar Con Multiles Salidas

  • 7/30/2019 Codigos Para Rabajar Con Multiles Salidas

    1/7

    Codigos para rabajar con multiles salidas

    ..

    Cdigo para trabajar con las entradas analogicas con el mux shied

    ..

    //Mux_Shield_AnalogIn_Example//http://mayhewlabs.com/arduino-mux-shield

    /*This example shows how to read and store all 48 pins as analog inputsinto arrays and print the results over serial.Multiplexer pin inputs that do not have a voltage reading (i.e nothingconnected) will have erratic values.

    To simplify this code further, one might use nested for loops or functioncalls.*/

    //Give convenient names to the control pins#define CONTROL0 5#define CONTROL1 4#define CONTROL2 3#define CONTROL3 2

    //Create arrays for data from the the MUXs//See the Arduino Array Reference:http://www.arduino.cc/en/Reference/Arrayint mux0array[16];int mux1array[16];int mux2array[16];

    void setup(){//Set MUX control pins to outputpinMode(CONTROL0, OUTPUT);pinMode(CONTROL1, OUTPUT);pinMode(CONTROL2, OUTPUT);pinMode(CONTROL3, OUTPUT);

    //Open the serial port at 28800 bpsSerial.begin(28800);

    }

    void loop(){//This for loop is used to scroll through and store the 16 inputs on

    the FIRST multiplexerfor (int i=0; i

  • 7/30/2019 Codigos Para Rabajar Con Multiles Salidas

    2/7

    //See the Aruino Bitshift Reference:http://www.arduino.cc/en/Reference/Bitshift

    digitalWrite(CONTROL0, (i&15)>>3);digitalWrite(CONTROL1, (i&7)>>2);digitalWrite(CONTROL2, (i&3)>>1);digitalWrite(CONTROL3, (i&1));

    //Read and store the input value at a location in the arraymux0array[i] = analogRead(0);

    }

    //This for loop is used to scroll through the SECOND multiplexerfor (int i=0; i>3);digitalWrite(CONTROL1, (i&7)>>2);digitalWrite(CONTROL2, (i&3)>>1);digitalWrite(CONTROL3, (i&1));mux1array[i] = analogRead(1);

    }

    //This for loop is used to scroll through the THIRD multiplexerfor (int i=0; i>3);digitalWrite(CONTROL1, (i&7)>>2);digitalWrite(CONTROL2, (i&3)>>1);digitalWrite(CONTROL3, (i&1));mux2array[i] = analogRead(2);

    }

    //The following lines are for printing out results of array0Serial.print("mux0array: ");for (int i=0; i

  • 7/30/2019 Codigos Para Rabajar Con Multiles Salidas

    3/7

    }

    .

    Cdigo para trabajar con entradas digitales del mux shield

    ..

    //Mux_Shield_DigitalIn_Example//http://mayhewlabs.com/arduino-mux-shield

    /*This example shows how to read and store all pins as digital inputs intoarrays and print the results over serial.Switches should be connected from ground to the pin input.Internal pull-up resistors are used on the inputs, so when a switch isdepressed, the readingchanges from 1 to 0, but to correct this logic, the digitalRead functionis corrected with '!'to actually store a 1 when a switch is depressed.

    To simplify this code further, one might use nested for loops or functioncalls.*/

    //Give convenient names to the control pins#define CONTROL0 5#define CONTROL1 4#define CONTROL2 3#define CONTROL3 2

    //Create arrays for data from the the MUXs//See the Arduino Array Reference:http://www.arduino.cc/en/Reference/Array

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

    void setup(){//Set MUX control pins to outputpinMode(CONTROL0, OUTPUT);pinMode(CONTROL1, OUTPUT);pinMode(CONTROL2, OUTPUT);pinMode(CONTROL3, OUTPUT);

    //Open the serial port at 28800 bps

    Serial.begin(28800);

    //Set analog pins to digital inputpinMode(14, INPUT);pinMode(15, INPUT);pinMode(16, INPUT);

    //Turn on pullup resistorsdigitalWrite(14, HIGH);digitalWrite(15, HIGH);

  • 7/30/2019 Codigos Para Rabajar Con Multiles Salidas

    4/7

    digitalWrite(16, HIGH);}

    void loop(){//This for loop is used to scroll through and store the 16 inputs on

    the FIRST multiplexerfor (int i=0; i>3);digitalWrite(CONTROL1, (i&7)>>2);digitalWrite(CONTROL2, (i&3)>>1);digitalWrite(CONTROL3, (i&1));

    //Read and store the input//Since internal pullup is on, the pin goes low on changing, so the

    value needs to be flipped from 0 to 1 (!)mux0array[i] = !digitalRead(14);

    }

    //This for loop is used to scroll through the SECOND multiplexerfor (int i=0; i>3);digitalWrite(CONTROL1, (i&7)>>2);digitalWrite(CONTROL2, (i&3)>>1);digitalWrite(CONTROL3, (i&1));

    mux1array[i] = !digitalRead(15);}

    //This for loop is used to scroll through the THIRD multiplexerfor (int i=0; i>3);digitalWrite(CONTROL1, (i&7)>>2);digitalWrite(CONTROL2, (i&3)>>1);digitalWrite(CONTROL3, (i&1));mux2array[i] = !digitalRead(16);

    }

    //The following lines are for printing out results of array0Serial.print("mux0array: ");for (int i=0; i

  • 7/30/2019 Codigos Para Rabajar Con Multiles Salidas

    5/7

    Serial.print("mux1array: ");for (int i=0; i

  • 7/30/2019 Codigos Para Rabajar Con Multiles Salidas

    6/7

    //Since all 3 multiplexers have the same control pins, the onemultiplexer data line we want to//talk to should be set to output and the other two multiplexer lines

    should be be 'bypassed' by//setting the pins to input

    //Turn on output to digital pin 14 (MUX 0) and turn off the other 2

    multiplexer data pinspinMode(14, OUTPUT);pinMode(15, INPUT);pinMode(16, INPUT);

    //This for loop is used to scroll through the FIRST multiplexerfor (int i=0; i>3); //S3digitalWrite(CONTROL1, (i&7)>>2); //S2digitalWrite(CONTROL2, (i&3)>>1); //S1digitalWrite(CONTROL3, (i&1)); //S0

    digitalWrite(14, HIGH);delay(100);digitalWrite(14, LOW);delay(100);

    }

    //Turn on output to digital pin 15 (MUX 1) and turn off the other 2multiplexer data pins

    pinMode(14, INPUT);pinMode(15, OUTPUT);pinMode(16, INPUT);

    //This for loop is used to scroll through the SECOND multiplexerfor (int i=0; i>3); //S3digitalWrite(CONTROL1, (i&7)>>2); //S2digitalWrite(CONTROL2, (i&3)>>1); //S1digitalWrite(CONTROL3, (i&1)); //S0

    digitalWrite(15, HIGH);

    delay(100);digitalWrite(15, LOW);delay(100);

    }

    //Turn on output to digital pin 16 (MUX 2) and turn off the other 2multiplexer data pinspinMode(14, INPUT);pinMode(15, INPUT);pinMode(16, OUTPUT);

  • 7/30/2019 Codigos Para Rabajar Con Multiles Salidas

    7/7

    //This for loop is used to scroll through the THIRD multiplexerfor (int i=0; i>3); //S3digitalWrite(CONTROL1, (i&7)>>2); //S2digitalWrite(CONTROL2, (i&3)>>1); //S1

    digitalWrite(CONTROL3, (i&1)); //S0

    digitalWrite(16, HIGH);delay(100);digitalWrite(16, LOW);delay(100);

    }}

    .