void fadein(int ipin){ for(int strength=1;strength<=255;strength++){ analogWrite(ipin,strength); delay(10); } } void fadeout(int ipin){ for(int strength=255;strength>=0;strength--){ analogWrite(ipin,strength); delay(10); } }
When I rewired my LED matrix, I made sure that the rows were attached to PWM pins. Now, when I set a red column to LOW. If I do analogWrite() with different values, I can make it different levels of brightness. Next, I want to try blending the colors. This is when I realized what was meant by the term "Common Anode," which is the type LED matrix I have. This term simply means that all of the colors in a given row are powered at the same time. By enabling the ground on the column of the desired color whatever PWM signal is sent through that row will apply to all grounded colors in that row. So how can I blend the colors?
The only thing that I can figure out is to:
- ground red "digitalWrite(LOW)"
- power the row with the appropriate PWM pulse "analogWrite(pin,value).
- Remove the ground from red "digitalWrite(HIGH)"
- set the row back to ground "analogWrite(pin,0)
It kinda works for 1 LED, but it is not very bright. Adding a 1 millisecond delay between the colors helped brighten them. Here's the real problem, more than one LED makes it flicker, beyond belief. I think I'm going to have to figure out how shift registers work. I had assumed that the reason that all of the examples that I have found used shift register because the Unos didn't have enough pins. I didn't think it'd be necessary since the Arduino Mega has so many pins. Maybe it's my code. Who knows?
No comments:
Post a Comment