NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Project Help and Ideas » Valentine Heart Project
January 26, 2010 by Phrank916 |
I was just wondering if anyone has modified this project for two rows of LEDs instead of one? I have a bunch of really small red and white LEDs that I wanted to use and create one row of white just inside the red one all the way around. Anyone possibly, maybe provide some code? I know it can be done, and I am pretty confident in the building and soldering, I just have no clue where to start with modifying the existing code. |
---|---|
January 26, 2010 by hevans (NerdKits Staff) |
Hi Phrank, That sounds like a pretty neat idea. Making it happen on the code side will take quite a bit of modification of the code side. Lets see if I can get you going in the right direction. The LED Heart shares a lot of code with the LED Array, so if you are familiar with that code this will be a lot easier. The LED Heart is basically an LED Array but with only one row. In the code this actually turns into two rows, one forward and one backward LED row. I think what you want to do is add a second physical row. The real trick is going to be modifying the code to hold the individual brightness data for each LED in your new row. Currently there is one array that holds the duty cycle for the one physical row. You can add another variable to hold the data for the second row, or you can make the current duty array a two dimensional array (array of arrays), that holds two rows ints. There might also be other ways to accomplish this, don't limit yourself to my suggestions here. Once you are holding the data for each array you should modify the helper functions like set_duty, full_duty, and ledarray_set to be able to set data for multiple rows (currently everything just assumes there is only one row). This is not a trivial project, but it is definitely possible, and you will definitely learn a lot in the process. Hope that gets you started in the right direction. Humberto |
January 28, 2010 by Phrank916 |
Humberto- Thanks for the pointers to get started. I need to get going on it soon because Feb 14 is coming quick and the code modification definitely sounds like a bit of work. I knew that it would basically be a "mash-up" of the heart and the ledarray. I am also thinking that I want to leave out the LCD stuff, and just have the blinkin' lights. I'll let you know my progress. Ted |
February 01, 2010 by Phrank916 |
So, I'm still trying to wrap my head around the code for the led heart and led array. I'm having trouble understanding the timer and how it's set to overflow. In the LED array there is this section in the ledarray_init function:
..which I know is setting the clock to overflow every 1.1ms. (took me a minute to figure out the math but I think i got it) So, in the LED heart code there is this section:
If I've done my computations correctly, this would set the 8bit timer to overflow every 13.8ms? Is this correct? And if so, is it just because there is only one row and not 5 that we can set the overflow longer? Also, I'm not sure where the 900Hz and 7000Hz figures come in or how they were computed? Is that just a rounded number? I'm slowly, slowly getting it, just a little confused here. Ted |
February 01, 2010 by Phrank916 |
wait no.. it would be .138ms, wouldn't it? Urgh.. |
February 01, 2010 by Phrank916 |
Ok, so if the timer for the ledheart is overflowing every .138ms then that would mean that it is overflowing 7207 times per second.. and that would be where we get the 7000Hz. Same with the Array, it's overflowing once every 1.1ms so that gives me 909.09 repeating or approx 900Hz. Alright! See, I'm slowly getting this! So, now my question is why does the LEDheart need to be refreshing so much faster than the LEDarray? Is it because of the 64 duty levels? |
February 01, 2010 by hevans (NerdKits Staff) |
Hi Phrank916, You are definitely on the right track. Great job! The timer was in fact set to a much faster because of the different brightness levels of the LEDs. For this project we wanted to get a smooth twinkling effect (fade in, then fade out), and if the display was only updating at 900Hz we got a choppy brightness jump every time it updated. At 7000Hz these jumps happen so fast your eye blends them together into a pretty fading effect. Humberto |
February 01, 2010 by Phrank916 |
Yeah, makes perfect sense, because with the array we're just worried about on or off. With this project we have 64 levels in between on and off. So, if I am able to add another row that also twinkles, would I need an even higher refresh? The next level is no prescalar which would give me 57600Hz! That seems like overkill. |
February 01, 2010 by hevans (NerdKits Staff) |
I would try it with the current prescaler first. I doubt that factor of 2 will have a significant impact on how it looks. I think the problem you will run into with no prescaler, is that the interrupt handler won't have time to finish executing before the interrupt fires again. We talk about this problem briefly in our interrupts tutorial. Humberto |
February 01, 2010 by Phrank916 |
Thanks for the super-fast feedback Humberto. You guys are awesome with your support and educating. I definitely need to go through the ps/2 keyboard tutorial and get a better handle on interrupts. Also, I know I need to learn a bit more regarding arrays. Is this the best place to start? How Stuff Works - C, Arrays Can you recommend any other array tutorials? |
February 02, 2010 by hevans (NerdKits Staff) |
Most C tutorials out there do a pretty good job of covering the basics of Arrays and Pointers. This one titled A Tutorial On Pointers And Arrays In C by Ted Jensen does a great job of covering the nitty gritty details. Humberto |
February 11, 2010 by Phrank916 |
Ok, Humberto- I think I've got it! After almost 2 weeks of staring glassy-eyed at this code, I think I've modified it to do 40 LEDs. I decided to go with two separate arrays: duty1 and duty2, the only problem I'm having now is rewriting the "twinkle" function efficiently so that it randomizes the value in both arrays without having to basically write it twice. I'm pretty sure I can do a FOR loop to make it run through twice, one time for each array, but I'm not sure how to get it to change between duty1 and duty2 depending on which iteration it's on. I haven't even touched that function yet, so it's still the same as the original code. So, here is the link to my latest modifications: Can you let me know if what I've done so far is even going to work? Especially the interrupt routine, I'm not sure if I did that right. Also, if you'd be so kind to give me a hint on solving the "twinkle" issue I would appreciate it very much! Ted |
February 12, 2010 by Phrank916 |
Yeah, in looking at it more, I think I just need to write a "twinkle1" and a "twinkle2" |
February 12, 2010 by Phrank916 |
I've re-uploaded my code for this project. The link above still works, just updated the code with the addition of a 2nd twinkle function. I honestly don't know if this is actually going to work, but I debugged it and got it to compile...so....I will report back after I build the hardware and get the code loaded on a chip, etc. Ted |
February 13, 2010 by Phrank916 |
Another Update: I put together 4 LEDs last night for testing: The first two of each row, so I basically only hooked up the two row wires and the first column wire. Two "twinkle" functions definitely did NOT work. I could comment out either of them and only one of the two sets would light. I added the blink_all function back from the original ledheart and that was working fine.. all 4 LEDs brightening and dimming. So, I've re-written the twinkle function and it all seems to be working, the only problem now, is that the LEDs in the 2nd row are turning all the way off and staying off for a good amount of time before the random brightening hits them and they will go bright for a half second (approx) and then go all the way out for a few long seconds again. I will have to repost my latest update to the code so anyone who is better in C can peek at it and maybe see where I'm going wrong. So, still working out the kinks, but I know I'm ALMOST to the final intended product. Ted |
February 13, 2010 by Rick_S |
I hope so... :D your deadline is tomorrow!! :D Rick |
February 13, 2010 by Phrank916 |
I figured out the problem with some of the LEDs going all the way out. I guess a duty cycle of 2 was too low of a least bright setting for some of my LEDs, but that's just a guess. So, I changed it to 4 in the code and now everything stays on and twinkles like it's supposed to! This was a fun one. Some mind numbingly hard code to comprehend at first, but stare at it long enough, and then walk away and think about it for awile, rinse, repeat and it all finally came together! I definitely learned a lot. Have fun with the 40 LED Valentine Heart. Ted |
February 13, 2010 by hevans (NerdKits Staff) |
Hi Ted, Glad you got it working! Great job! Humberto |
Please log in to post a reply.
Did you know that hobby servos are controlled through a particular kind of PWM (Pulse Width Modulation) signal? Learn more...
|