problems with multiplexing leds

So I need to finish a prototype for tomorrow morning (its 3am). It should feature quite some leds which all need be controlled individually. I started with a 8x8 matrix but since the time I think a 4x4 matrix is better. My problem is that I can’t seem to get how to control the leds individually. The codes I enter in dataToSend do not match my expected outcomes, so if anyone would be able to help me out to understand them.

The matrix will be used in combination with a potentiometer, the range of the potentiometer will be divided over the amount of leds. Once you reach a new value it has to turn as much leds on corresponding to how far you turned the potentiometer.

//LED TEST w/ 74HC595
//by Amanda Ghassaei 2012
//https://www.instructables.com/id/Multiplexing-with-Arduino-and-the-74HC595/

/*
 * 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 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
*/

//this code will light up each led in the 4x4 matrix one at a time


//pin connections- the #define tag will replace all instances of "latchPin" in your code with A1 (and so on)
#define latchPin A1
#define clockPin A0
#define dataPin A2

//looping variables
byte i;
byte j;

//storage variable
byte dataToSend;

void setup() {
  //set pins as output
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
}

void loop() {
  
  for (i=0;i<4;i++){
    
    for (j=0;j<4;j++){
      
      //bit manipulation (more info at http://arduino.cc/en/Reference/Bitshift ,  http://arduino.cc/en/Reference/BitwiseXorNot , and http://arduino.cc/en/Reference/BitwiseAnd)
      dataToSend = (11111111);//preprare byte (series of 8 bits) to send to 74HC595
      //for example when i =2, j = 3,
      //dataToSend = (1 << 6) | (15 & ~(1 << 3));
      //dataToSend = 01000000 | (15 & ~(00001000));
      //dataToSend = 01000000 | (15 & 11110111);
      //dataToSend = 01000000 | (15 & 11110111);
      //dataToSend = 01000000 | 00000111;
      //dataToSend = 01000111;
      //the first four bits of dataToSend go to the four rows (anodes) of the LED matrix- only one is set high and the rest are set to ground
      //the last four bits of dataToSend go to the four columns (cathodes) of the LED matrix- only one is set to ground and the rest are high
      //this means that going through i = 0 to 3 and j = 0 to three with light up each led once
      
      // setlatch pin low so the LEDs don't change while sending in bits
      digitalWrite(latchPin, LOW);
      // shift out the bits of dataToSend to the 74HC595
      shiftOut(dataPin, clockPin, LSBFIRST, dataToSend);
      //set latch pin high- this sends data to outputs so the LEDs will light up
      digitalWrite(latchPin, HIGH);
      
      delay(500);//wait
    }
  }
  
}

Ok, so it's not URGENT like so many others we see here. (Just kidding.)

      delay(500);//wait

Wait for what? This is inside your inner loop, so it's going to run really really slowly.

Which matrix do you have? Which Arduino?

Have you read and understood the comment in the code about rows and columns?

MorganS:
Ok, so it’s not URGENT like so many others we see here. (Just kidding.)
Wait for what? This is inside your inner loop, so it’s going to run really really slowly.

Which matrix do you have? Which Arduino?

Have you read and understood the comment in the code about rows and columns?

I built a led matrix myself with a 74HC595, I have a Arduino Uno.

I think I understand it, what I get from it is if you make the first row and the first column 1 óne Led will turn on (top left). But this doesnt work.

Edit: I also tried to do it with just 10 leds and no multiplexing, but nothing happened when I turned the potentiometer (I checked that it is read).

prototype_MOD07.ino (2.52 KB)

Define "Doesn't work". Do any LEDs come on?

MorganS:
Define "Doesn't work". Do any LEDs come on?

Yes, I tried a whole lot a of different combinations (tried to document it, then discovered that would be a sh*tload of work), but they all seemed quite random.
The only one I did write down is that 10000100 gives only the top left led on, 11000000 does the same.

Then you need to check your wiring.

MorganS:
Then you need to check your wiring.

Okay, I will thanks!
Could you also check my code I put under my second comment in this thread. Im sorry its so simple which is probably why it doesnt work, but my coding skills dont go much further than if then statements.

Google, Friend can it be but mislead you it can!

Have a look here.

Sounds like your project

Daz

Are you sound in how a matrix scans?
If not this might help you
http://www.thebox.myzen.co.uk/Workshop/LED_Matrix.html

Hi,
Have you go all your LED wired the correct way round?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile:

I have the feeling it's by now about a day past OP's deadline so either the project is finished or it's dead - either way I'm not expecting to hear from OP any more.