RGB Fading Using 3 LEDs and PWM


Closed Thread
Results 1 to 28 of 28

Hybrid View

  1. #1
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    [] mean an array.

    what's an array? roughly it's a variable with multiple value... well not really

    let's say we define HELLO VAR BYTE[10] Hello can contain 10 different value.

    Hello[0]=1
    hello[1]=2
    hello[2]=3

    and blah blah blah... so if you recall hello[1] you'll get 2.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  2. #2
    JDM160's Avatar
    JDM160 Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks very much for the reply... unfortunately I'm still lost :-(

    The part I'm having trouble with is:

    ------------------------------------------
    ledPWM:
    For y = 0 to 2
    Select Case y
    Case 0
    pwm red, rbgarray[y], 1
    case 1
    pwm green, rbgarray[y], 1
    case 2
    pwm blue, rbgarray[y], 1
    end select
    ------------------------------------------

    I'm under the impression that this program will cycle through the different colors of the rainbow using three different LEDs (ports) - naturally red, green and blue, and varying the duty cycle to each to create the dimming and cycling effect.

    I don't see how this part of the code (which calls the PWM of the individual ports) varies the duty cycle differently for each color. Can anybody explain how this works? Or am I misunderstanding the purpose of this program?

    Oh, by the way, I have defined the ports "red, green, and blue" as you can see in the code above..

    Thanks again!

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    The best way to learn, is to place the program on a PIC and see what's happen with. Try to modify it and see how it affect different parts. You can't blow anything. The worst situation will be 'syntax error' or something like that.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    JDM160's Avatar
    JDM160 Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e
    The best way to learn, is to place the program on a PIC and see what's happen with. Try to modify it and see how it affect different parts. You can't blow anything. The worst situation will be 'syntax error' or something like that.
    Yea, I know! My stuff is in the mail though.. doh! And I really am trying to understand how this program works. It does independantly vary the duty cycle of the different colors right? HOW!?!

    I really appreciate your time - I can't wait to get my PICs.

  5. #5
    JDM160's Avatar
    JDM160 Guest


    Did you find this post helpful? Yes | No

    Default

    Eureka!

    I got it!

    ------------------------------------------
    ledPWM:
    For y = 0 to 2
    Select Case y
    Case 0
    pwm red, rbgarray[y], 1
    case 1
    pwm green, rbgarray[y], 1
    case 2
    pwm blue, rbgarray[y], 1
    end select
    ------------------------------------------

    I was having trouble realizing that the nested Case statement in the For statement was hitting "red" with rbgarray[1], "green" with rbgarray[2] and "blue" with rbgarray[3] - which are each different values between 1-256!

    It's like the sun rising, in my mind..

  6. #6
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    Although this sequence works reasonably well. Why do the LEDs when they have faded to OFF remain slightly lit when realy they should be OFF?

    Also, during the sequence, one LED jumps quickly to another, I have it when BLUE goes OFF, it jumps to RED quickly, then goes OFF again. Are others getting the same, it is quite quick.

    Is there any other RGB sequences out there that perform a similar task??

    Cheers,

    Steve

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    i think it's more a math calculation overflow... try to do some simple calculation when 'rainbowval' is reaching something like 200,230,240... or lower. if you have ICD capability it's easy to see whats happen. MicroCode free version have ICD for 16F628.

    See Bruce's website Here for the ICD explanation

    Here to buy full version or to download free version Of MicroCode Studio


    it's worth every $ you'll place on this program.
    Last edited by mister_e; - 8th March 2005 at 03:50.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. RGB Fading Using 3 LEDs and PWM
    By _abello in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 19th April 2006, 15:50
  2. Slowing Down RGB PWM Routine
    By Tissy in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th March 2005, 09:22
  3. Tidying Up PWM Routine
    By Tissy in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 21st February 2005, 00:26
  4. PWM conflict
    By Srigopal007 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 1st September 2004, 15:18
  5. pics with 3 hardware PWM ports
    By CBUK in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th August 2004, 00:14

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts