Hi all, I faced a problem, you need to connect 49 LEDs to the board (standard 3.4V 20mA). Saw how to make a cube of 512 LEDs, but there soldered them, and I need to keep the LEDs on the wires + is not quite clear. On the Internet found how to do something similar using shift registers, but again, did not understand how it works.
As I understand it: let's imagine that we have a table of LEDs 7x7, in each column we connect their +, and in each row -. And then, to turn on the LED in row i and column j, we need to feed the shift register with minus (1 << i), with plus - (1 << j). But I'm not sure that this will work for the shift register with minus, I didn't understand how to connect them to each other.
The first thing you need is a 10+A power supply for that many LEDs 0.020 * 512.
Before you think about a multiplexer, draw a schematic and thing of hooking a board with at least 14 free IO pins (Uno, Nano, Mega,...) to it (with current limiting resistors.
Then consider what each pin's HIGH/LOW status needs to be to turn on a single LED--One and only one column needs to be HIGH to feed the LED's Anode, and one and only row needs to be LOW to let power flow through the particular LED's cathode. It isn't + and - that the multiplexer outputs, it is just HIGH/+ and LOW/GND. Once that begins to make sense or you run out of pins, you can think of how to do it with a multiplexer.
https://docs.arduino.cc/built-in-examples/display/RowColumnScanning/
A physical matrix arrangement doesn't have to be wired as a matrix. ![]()
Serial addressing is far more common. With 3 output pins you can individually address as many LEDs as you want. Besides general-purpose shift registers, there are special-purpose serial LED drivers. I have a project with 48 LEDs driven by 6 MAX6968 chips.
NeoPixels (WS2812) are also super-popular. They are addressed serially with only one data line. Normally they come as LED strips but they are also sold individually.
Hello again, Nik!
You should interpret the homework questions in your own understanding. : )
You have a couple things going on here...
That's a matrix with rows of Cathodes tied to one pin for each row, and columns of Anodes tied to one pin for each column. To turn all LEDs off, set all Cathode rows HIGH and set all Anode columns LOW. To turn one LED on, set its Cathode row LOW and its Anode column HIGH... you must keep "turning on" that LED. You will need two shift registers for a 7x7, one for Cathodes, one for Anodes.
You can directly address every LED by moving binary values into the shift register. All cathodes will be tied to ground. This would take 6 shift registers (49 anodes).
How do you light multiple LEDs on a matrix in such a case? The code from the link can do it, but won't fast switching on and off of LEDs affect their performance? Will this scheme and code work in reality (I don't have enough components, so I can't test it yet)?
const int anodes[] = {2, 3, 4, 5, 6, 7, 8};
const int cathodes[] = {9, 10, 11, 12, 13, A0, A1};
const int C = 7;
bool pixels[7][7];
void setup() {
// put your setup code here, to run once:
for (int i = 0; i < C; i++) {
pinMode(anodes[i], OUTPUT);
pinMode(cathodes[i], OUTPUT);
digitalWrite(cathodes[i], HIGH);
}
for (int i = 0; i < 7; i++) {
for (int j = 0; j < 7; j++) {
pixels[i][j] = HIGH;
}
}
}
void display() {
for (int thisAnode = 0; thisAnode < 7; thisAnode++) {
// take the row pin (anode) high:
digitalWrite(anodes[thisAnode], HIGH);
// iterate over the cols (cathodes):
for (int thisCathode = 0; thisCathode < 7; thisCathode++) {
// get the state of the current pixel;
int thisPixel = pixels[thisAnode][thisCathode];
// when the row is HIGH and the col is LOW,
// the LED where they meet turns on:
digitalWrite(cathodes[thisCathode], thisPixel);
// turn the pixel off:
if (thisPixel == LOW) {
digitalWrite(cathodes[thisCathode], HIGH);
}
}
// take the row pin low to turn off the whole row:
digitalWrite(anodes[thisAnode], LOW);
}
}
void loop() {
pixels[ind / 7][ind % 7] = HIGH;
ind++;
ind %= 49;
pixels[ind / 7][ind % 7] = LOW;
unsigned long timer = millis();
while (millis() - timer < 100) {
display();
}
}
You shoudn't do it simultaneously because it becomes ambiguous and you will overload the drivers behind the pins on the arduino. Folks solve it by scanning and only turning on single LEDs (or the relevant leds in a single column/row, if the drivers are strong enough)
The ambiguity is that if you try to light up 1,1 and 4,4 simultaneously, then you are also powering up 1,4 and 4,1.
This is true.
The program needs to clear the previous LED, set the next LED and repeat... Brightness will be effected by speed. It is faster to clear the individual LED, not the whole matrix.
void LEDs1and4() {
clearMatrix();
digitalWrite(aPin[0], HIGH); // LED "1" anode
digitalWrite(cPin[0], LOW); // LED "1" cathode
clearMatrix();
digitalWrite(aPin[3], HIGH); // LED "4" anode
digitalWrite(cPin[3], LOW); // LED "4" cathode
}
void clearMatrix() { // reverse bias all LEDs
for (int i = 0; i < sizeof(aPin); i++) {
digitalWrite(aPin[i], LOW); // Anodes off
}
for (int i = 0; i < sizeof(cPin); i++) {
digitalWrite(cPin[i], HIGH); // Cathodes off
}
}
Can you please explain why you are using 10 kilo ohm resistors?
Current limiting so the LED does not sink too much current. The value is dependent on your components.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.

