This wiki has been archived and made read-only.
For up-to-date information about TkkrLab and it's projects please visit our main website at tkkrlab.nl.

Arduino multiplexing

From

Jump to: navigation, search

This was for Teaching my self the art of multiplexing, didn't read much on multiplexing online had my own ideas on how it works, just had to read up on

shift register, tested

my idea's on how it works and bam it does work!

I hope this will be usefull to someone in turn.

preview

Hardware:

Hardware you need:

  • a Arduino.
  • a Breadboard.
  • 2x bc547
  • 16x leds
  • 1x 74hc595 (shiftregister)
  • 18x 220 ohm resistors
  • a lot of wires/jumperwires.

Here's a picture of the schematic/breadboard layout: Schematic arduino 16bit counter multiplexing 1 shift register cc.png


What it looked like on my breadboard:

one thing I forgot on the picture is that you can just connect the power lines on the breadboard with the arduino, keep in mind red is positive black negative/0v.


Arduino multiplexing.jpg

Software:

here is the code you'll need to upload to the arduino,

basicly what this code does is count to 65536.

then it will quickly write the first 8 bits to the first led array by turning it on really quick.

then it will turn the the first array off really quick, and quickly turn the second array of leds on and write the last 8 bits.

then it will repeat the step till it reaches 65536 in binary which by my calculation's is gonna take 18 hours!


//This program is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.

//can I give myself some unshamed credits?
//written and made by Duality (arduino forum)

int latchpin = 8;
int clockpin = 12;
int datapin = 11;

int switch1 = 2;
int switch2 = 4;

//unsigned int addr because we then can count to 2^16 positive instead
// of halve of it going negative.
unsigned int addr = 0;

void setup(){
//we set the pin modes.
  pinMode(latchpin, OUTPUT);
  pinMode(clockpin, OUTPUT);
  pinMode(datapin, OUTPUT);
  pinMode(switch1, OUTPUT);
  pinMode(switch2, OUTPUT);
}

  void loop(){
    // in this for loop we count to 65536 and make addr equal to i.
    for (int i = 0; addr <= 65536; i++) {
      addr = i;
     //we write addr to the leds.
      writeout();
    }
    
  }
  
  void writeout(){
     for (int y = 0; y < 1000; y++){
        //we enable writing to the shift register.
        digitalWrite(latchpin, LOW);
        //we set switch1 high so the data gets written to the first led array.
        digitalWrite(switch1, HIGH);
        //we write out the first 8 bits of the total of addr.
        shiftOut(datapin, clockpin, MSBFIRST, (addr >> 8));
        //we close the switch1 led array.
        digitalWrite(switch1, LOW);
        //we disable writing to the shift register.
        digitalWrite(latchpin, HIGH);
        //then we wait a bit.
        delayMicroseconds(500);


        //basically the same happens here as above, but switch2 will activate led array 2.
        digitalWrite(latchpin, LOW);
        digitalWrite(switch2, HIGH);
        //instead of writing the first 8 bits, we use a little calculation to write the last 8 bits of the total of addr.
        shiftOut(datapin, clockpin, MSBFIRST, (addr & 255));
        digitalWrite(switch2, LOW);
        digitalWrite(latchpin, HIGH);
        delayMicroseconds(500);

     }
  }