Single PIC to Blink 5 LEDs Independently?


Results 1 to 40 of 69

Threaded View

  1. #23


    Did you find this post helpful? Yes | No

    Default Re: Single PIC to Blink 5 LEDs Independently?

    As the purpose of this project is to create 5 blinking LEDs that simulate old 1960's Christmas tree lights, I've added the following code to fade in/out the LED:

    Code:
    IsOn       VAR BYTE[LEDCount]
    i          VAR BYTE
    
    FOR x = 0 to (LEDCount - 1)         ; set initial LED state to OFF
        IsOn(x) = 0
    NEXT x
    
    ;----[Main Program Loop]----------------------------------------
    Main:
        x = (x + 1) // LEDcount
        IF LoopLED(x) < OnTime(x) THEN
            IF IsOn(x) = 1 THEN
               READ Brightness + x, Bright(x)
            ELSE
               IsOn(x) = 1
               ; Fade up LED to set brightness
               FOR i = 0 to Bright(x) Step 1
                   Bright(x) = i
                   PAUSE 20
               NEXT i
            ENDIF
        ELSE
            IF IsOn(x) = 1 THEN
               IsOn(x) = 0
               ; Fade out LED
               FOR i = Bright(x) to 0 Step -1
                   Bright(x) = i
                   PAUSE 20
               NEXT i
            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
    I'll program a 12F683 this afternoon and see what it looks like.
    Last edited by RossWaddell; - 29th March 2014 at 15:01.

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 : 1

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