So heres my issue. I'm trying to make a library that will light up leds depending on a few things. The only issue is I need to do that to 128 leds. I would be able to get away with 64(16 on max at all times) i guess but the only real way was through shift registers. Basically i have a number (1-128) and i need to translate that to an led. The way i came up with is a huge array:
int leds[128] =
{ 0,0,1,0,0,0,1 ...(and so on) ,0,0 }
where leds[0] is the first led, and leds[128] was the last
in searching for a solution of how to write that i found https://www.arduino.cc/en/Tutorial/ShftOut23
However that only says that i need to write it in hex. Any ideas?
Hi, its not clear what you want to do. What did you mean by "16 on max at all times"? Later you seem to say that only one led out of 128 will be on, indicating a number 1..128.
What kind of Arduino do you have?
Do you need the leds to fade or just be on/off?
Why do you want to make a library?
If you want only one led on at a time, there is a way to do this without any extra chips using a technique called Charlieplexing. That will need 12 output pins and 12 resistors only.
PaulRB:
Hi, its not clear what you want to do. What did you mean by "16 on max at all times"? Later you seem to say that only one led out of 128 will be on, indicating a number 1..128.
By this:
I need to do that to 128 leds. I would be able to get away with 64(16 on max at all times)
I assumed he meant. He wants to control 128 leds but could live with using only 64 and only 16 are on at any given point in time.
bperrybap:
By this:I assumed he meant. He wants to control 128 leds but could live with using only 64 and only 16 are on at any given point in time.
You could be right Bill. If so, charlieplexing and multiplexing could be combined to allow 16 leds at once, with the addition of 12 transistors and significantly more sketch complexity. Bob's suggestion of 2 x max7219 would probably be easier.
Sorry, i almost forgot about this, Yes i meant That only a max of 16 leds would be on, i have an arduino mega(which is why i need more outputs). I'm sort of confused though how i would get 64 outputs from the 8 on the shift register?
Changing the "pixel" map from one per int to one per bit in multiple bytes changes how the "pixel" data is accessed which requires math to figure out which byte and which bit to test/set vs just a simple index.
While it isn't hard, that too will be different.
Just switching from an int to a uint8_t on the initial array above, while still wasteful, could save half the memory with no other code changes.
--- bill
It sounds to me like the OP wants to send this data out to either shift registers or max7219. However the data is held in memory, it will have to be packed into bytes before that can happen, so some bit manipulation will have to be done, sooner or later.