Well KermM pointed out some nice rgb leds on Dealextreme the other day ,and they have been something I have been wanting to mess with and toy around with for a while. I got some money and bought a few. Now while I wait for Dealextreme to get them to me i figured i might as well brush up on my very bad c skills and dust off my msp430 and code something for it that deals with PWM so I can create a Partymode like setup of my own Very Happy

Well I read the wikipedia article on PWM and it makes sense I get what you are doing. but I don't get how to implement it at all. or any of the physical math and numbers behind it to help me code anything for it. So yeah anyone able to help lead the way for some colorful fun for me by explaining PWM and stuff?
Assuming this is the same idea as PWM for sound, what you do is have some period of N, and some level of brightness X (which is from 0 to N). Then you implement it like this:


Code:
turn_off_LED();
while (keep_executing)
{
  wait(N - X);
  turn_on_LED();
  wait(X);
  turn_off_LED();
}


If you have accurate interrupts available, those could be useful if you want this to run in the background.

Edit: Actually, since you have to control 3 colors, maybe do something like this. My pseudofunction set_color_levels() takes 3 arguments of 0 or 1 to turn off or on each LED color.

Code:
int r_level, g_level, b_level;
while(keep_executing)
{
  for(int i = period; i >= 0; i--)
    set_color_levels(i < r_level, i < b_level, i < g_level);
}
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement