Single PIC to Blink 5 LEDs Independently?


Closed Thread
Results 1 to 40 of 69

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default Re: Single PIC to Blink 5 LEDs Independently?

    Do you mean something like this (I'm sure there's more elegant code, but ...):

    Code:
    temp  VAR  WORD
    
    ;----[Main Program Loop]----------------------------------------
    Main:
        x = (x + 1) // LEDcount
        IF LoopLED(x) < OnTime(x) THEN
            READ Brightness + x, temp
            IF Bright(x) < temp THEN
                Bright(x) = Bright(x) + 2
            ELSE
                Bright(x) = temp
            ENDIF
        ELSE
            IF Bright(x) > 0 THEN
                Bright(x) = Bright(x) - 2
            ELSE
                Bright(x) = 0
            ENDIF
        ENDIF
        LoopLED(x) = (LoopLED(x) + 1) // (OnTime(x) + OffTime(x))
        #IFDEF USE_RANDOM_SEQUENCE
            RandPeriod(x) = RandPeriod(x) - 1
            IF RandPeriod(x) = 0 THEN
                READ RandPeriods+(x<<1), WORD RandPeriod(x)
                RANDOM RND
                OnTime(x) = (MAX_ON - MIN_ON)* RND.HighByte / 255 + MIN_ON
                OffTime(x)= (MAX_OFF - MIN_OFF)* RND.LowByte / 255 + MIN_OFF
            ENDIF
        #ENDIF
    
        IF x != (LEDcount - 1) THEN Main
    
    Waiting: IF !TMR0IF THEN Waiting
        TMR0 = 99
        TMR0IF = 0
    GOTO Main

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    That's Perfect!!

    May take more than 2 for the Speed, but well done!
    DT

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: Single PIC to Blink 5 LEDs Independently?

    In preparation for the next step I had written this almost identical code.
    There are a few differences that might be of benefit.
    Code:
    MaxBright      VAR BYTE
    FadeSpeed      CON 20
    
    ;----[Main Program Loop]----------------------------------------
    Main:
        x = (x + 1) // LEDcount
        IF LoopLED(x) < OnTime(x) THEN
            READ Brightness + x, MaxBright
            IF Bright(x) <= (MaxBright - FadeSpeed) THEN
                Bright(x) = Bright(x) + FadeSpeed
            ELSE
                Bright(x) = Maxbright
            ENDIF
        ELSE
            IF Bright(x) >= FadeSpeed THEN
                Bright(x) = Bright(x) - FadeSpeed
            ELSE
                Bright(x) = 0
            ENDIF
        ENDIF
    DT

Similar Threads

  1. Single button function
    By DynamoBen in forum mel PIC BASIC Pro
    Replies: 40
    Last Post: - 4th April 2020, 18:33
  2. How to blink 8 LEDs at different rates- concurrently?
    By rmteo in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 26th April 2010, 23:47
  3. single sided PCB
    By schu4647 in forum General
    Replies: 1
    Last Post: - 10th December 2008, 18:22
  4. Can't Blink 2 LEDs
    By dfort in forum mel PIC BASIC
    Replies: 2
    Last Post: - 5th March 2008, 22:36
  5. Tx and Rx of Single Pin PIC's
    By Dwayne in forum Code Examples
    Replies: 0
    Last Post: - 26th May 2004, 14:55

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