I have been trying some different code to get this figured out. I already had some 74HC595 chips so I am trying to use those if possible. Not really getting anywhere so far. I found a similar code online but they are only using one chip (https://www.instructables.com/id/Multiplexing-with-Arduino-and-the-74HC595/)
I have made a 3x3 matrix with the columns connected to the + pins of the LEDs and the rows connected to the - pins. The negative pins are hooked into a second chip on pins Qa, Qb, and Qc. The columns are Qa, Qb, and Qc of the first chip.
Here is the code I used. I am getting the 3rd LED in the first column and the 3rd LED in the 3rd column to be mostly be on but the 2nd LED in each of those columns is blinking intermittently. Can't figure out why?
//pin connections- the #define tag will replace all instances of "latchPin" in your code with A1 (and so on)
#define latchPin 41
#define clockPin 40
#define dataPin 38
//looping variables
byte i;
byte j;
//storage variable
byte dataToSend, dataToSend2;
void setup() {
//set pins as output
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop() {
for (i=0;i<8;i++){
for (j=0;j<8;j++){
//bit manipulation (more info at << - Arduino Reference , ~ - Arduino Reference , and & - Arduino Reference)
//dataToSend = (1 << (i+4)) | (15 & ~(1 << j));//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
dataToSend = 1111111000000001;//preprare byte (series of 8 bits) to send to 74HC595
dataToSend2 = 11111011;//preprare byte (series of 8 bits) to send to 74HC595
// 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);
//shiftOut(dataPin, clockPin, LSBFIRST, dataToSend2);
//set latch pin high- this sends data to outputs so the LEDs will light up
digitalWrite(latchPin, HIGH);
delay(10);//wait
}
}
}