Shop OBEX P1 Docs P2 Docs Learn Events
RGB LED Light bar project. Need some help with basic coding. — Parallax Forums

RGB LED Light bar project. Need some help with basic coding.

Kd7laxKd7lax Posts: 42
edited 2008-12-18 19:57 in BASIC Stamp
Hello All,
So one of my newest projects is some RGB led light bars. This project is for lighting effect inside my computer case.

For now I have been playing around with one RGB LED to get the hang of coding for it, eventually I would like to have some kind of random color generator that could be activated by pressing a button.

I have been using code from some tutorials for the SX and BS2 such as (all the testing is being done on my bs2 OEM)

Start:
   DO
        FOR duty = 0 TO 254
             PWM Blue, duty, 50
        NEXT
        FOR duty =254 TO 0
             PWM Blue, duty, 50 ...etc





Just fading in and out solid colors Red, Green and Blue. How would I vary these colors?

I have done other colors by using:
 NEXT
        FOR duty = 0 TO 254
             PWM Red, duty, 30
             PWM Blue, duty, 30
        NEXT
        FOR duty =254 TO 0
             PWM Red, duty, 30
             PWM Blue, duty, 30
             NEXT


But when doing this the light gets all flashy... not sure why?

So any way I guess my question is: Can I vary the colors just using a BS2 or a SX? and if so how? Or if I can't what other kind of hardware do I need?

Sorry if this is kind of a noob question, Its been a while since I have played around with RGB stuff.

Thank you in advanced for the replies.
-Mike

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Visit my website @ www.kd7lax.com- Devoted to ham radio

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-12-18 19:57
    You need to cut back on the PWM time and alternate between the colors to·speeds short enough that the eye cannot see the difference, the persistence of vision threshold, which is approx 30Hz (33ms).
    So, I'd go with:
    PWM Red, duty, 15
    PWM Blue, duty, 15
     
    -- or --
     
    PWM Red, duty_r, 15
    PWM Blue, duty_b, 15
    

    The PWM Red time + PWM Blue time = 30ms.

    When you're ready·to go R-G-B:
    PWM Red, duty_r, 10
    PWM Blue, duty_b, 10
    PWM Green, duty_g, 10
    


    I've done this differently, but I didn't want to·steer you away from your chosen PWM command paradigm.

    Post Edit -- I wouldn't be using the R-C circuit, just the raw PWM output.

    
    
    duty_r = 255
    duty_b = 10
    FOR color_time_on = 0 TO 255
      PWM Red, duty_r, 15
      PWM Blu, duty_b, 15
      NEXT
     
    duty_r = 125
    duty_b = 125
    FOR color_time_on = 0 TO 255
      PWM Red, duty_r, 15
      PWM Blu, duty_b, 15
      NEXT
     
    duty_r = 100
    duty_b = 200
    FOR color_time_on = 0 TO 255
      PWM Red, duty_r, 15
      PWM Blu, duty_b, 15
      NEXT
    
    
     
    duty_r = 10
    duty_b = 255
    FOR color_time_on = 0 TO 255
      PWM Red, duty_r, 15
      PWM Blu, duty_b, 15
      NEXT
    
    
    
    




    Post Edited (PJ Allen) : 12/18/2008 8:08:03 PM GMT
Sign In or Register to comment.