How many times the loop turns for Darrel's "Kylon" LED chaser?


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2013
    Posts
    1,078

    Default How many times the loop turns for Darrel's "Kylon" LED chaser?

    Hello.

    I want to use this code for my christmas light:

    http://www.picbasic.co.uk/forum/showthread.php?t=10564

    I've modified it for 5 leds and it works fine. However, I want it to not spin forever, but change some values, like speed and trails after several runs.

    All the magic is done via this code as I can guess:

    Code:
    Main:    if LoopCount = TracerSpeed then             ; __[ Cylon/Kitt Scanner ]__      LoopCount = 0      BAM_DUTY(NextLED)=Brightness      if TraceDIR then                          ; if scanning left        NextLED = NextLED - 1        if NextLED = 0 then TraceDIR = 0      else                                      ; else scanning right        NextLED = NextLED + 1        if NextLED = BAM_COUNT-1 then TraceDIR = 1      endif    endif        FOR Idx = 0 to BAM_COUNT - 1                ; Drain all dutycycles       IF BAM_DUTY(Idx) > 0 then           BAM_DUTY(Idx)=BAM_DUTY(Idx)*DrainSpeed/(DrainSpeed+1)       ENDIF    NEXT Idx    pause Speed    LoopCount = LoopCount + 1GOTO Main
    It all works fine, besides that I can't find, how many times it loops for complete cycle? - I mean, single run from left to right and back, with all fades.Any ideas?

  2. #2
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: How many times the loop turns for Darrel's "Kylon" LED chaser?

    Copy-paste screwed up the code, here it is:

    Code:
    Speed       CON 24        ; Smaller=Faster
    TracerSpeed CON 15        ; Smaller=Faster Left/Right
    Brightness  CON 255       ; Tracers DutyCycle
    DrainSpeed  CON 30        ; Smaller=Shorter Trail
    BAM_COUNT = 5
    
    
    Main:
        if LoopCount = TracerSpeed then             ; __[ Cylon/Kitt Scanner ]__
          LoopCount = 0
          BAM_DUTY(NextLED)=Brightness
          if TraceDIR then                          ; if scanning left
            NextLED = NextLED - 1
            if NextLED = 0 then TraceDIR = 0
          else                                      ; else scanning right
            NextLED = NextLED + 1
            if NextLED = BAM_COUNT-1 then TraceDIR = 1
          endif
        endif
        
        FOR Idx = 0 to BAM_COUNT - 1                ; Drain all dutycycles
           IF BAM_DUTY(Idx) > 0 then
               BAM_DUTY(Idx)=BAM_DUTY(Idx)*DrainSpeed/(DrainSpeed+1)
           ENDIF
        NEXT Idx
        pause Speed
        LoopCount = LoopCount + 1
    GOTO Main
    Last edited by CuriousOne; - 14th November 2021 at 09:03.

  3. #3
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: How many times the loop turns for Darrel's "Kylon" LED chaser?

    To make it adjustable, change the CON values to VAR values. You will have to initialize them to some value (try starting with Daryl's CON values), then somewhere change them as you see fit. First play with different values in Daryl's code for the CONs and see how it affects the display. On a separate note, BAM_COUNT should have been Declared:
    Code:
    BAM_COUNT VAR BYTE
    BAM_COUNT = 5

  4. #4
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: How many times the loop turns for Darrel's "Kylon" LED chaser?

    The values of these settings in my example provide the effect I need.
    I just need to enclose that loop into FOR-NEXT, to be able to have control over it.
    And the issue is, I can't count, how many times loop turns around, to do single cycle (from left to right and back)

  5. #5
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: How many times the loop turns for Darrel's "Kylon" LED chaser?

    Ok, try adding a few lines:
    Code:
    Speed       CON 24        ; Smaller=Faster
    TracerSpeed CON 15        ; Smaller=Faster 
    Left/RightBrightness  CON 255       ; Tracers 
    DutyCycleDrainSpeed  CON 30        ; Smaller=Shorter 
    TrailBAM_COUNT = 5
    Cycle VAR BYTE  ;Count Full Cycles
    
    Main:
        if LoopCount = TracerSpeed then             ; __[ Cylon/Kitt Scanner ]__
          LoopCount = 0
          BAM_DUTY(NextLED)=Brightness
          if TraceDIR then                          ; if scanning left
            NextLED = NextLED - 1
            if NextLED = 0 then
            TraceDIR = 0
            Cycle = Cycle + 1
            IF Cycle = xx THEN
              Do Something
              Cycle = 0
            ENDIF
          else                                      ; else scanning right
            NextLED = NextLED + 1
            if NextLED = BAM_COUNT-1 then
            TraceDIR = 1
           endif
        endif
       FOR Idx = 0 to BAM_COUNT - 1                ; Drain all dutycycles
           IF BAM_DUTY(Idx) > 0 then
               BAM_DUTY(Idx)=BAM_DUTY(Idx)*DrainSpeed/(DrainSpeed+1)
           ENDIF
        NEXT Idx
          pause Speed
          LoopCount = LoopCount + 1
    GOTO Main
    This should increment your Cycle variable after a full left swing.

  6. #6
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: How many times the loop turns for Darrel's "Kylon" LED chaser?

    Thanks! will give it a try - currently have no monitoring capabilities connected to the PIC. Only way to interact is to write data to EEPROM and check the value via pickit 3 standalone programmer. Will try to add write routine to your code...

    This circuit will be used to upgrade old Christmas tree decoration, shaped like a red star

    Name:  in31b.jpg
Views: 276
Size:  271.9 KB

  7. #7
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: How many times the loop turns for Darrel's "Kylon" LED chaser?

    I had to gave up with that code, because on a larger physical size, discrete steps were quite visible.
    So I did another code instead, which works fine. Here's example.




    But I have a question. What if I use faster PIC, something from 18F series, running at 64mhz.
    Maybe it is possible to mod this code to have at least 10 bit resolution, instead of 8 ?

Similar Threads

  1. how to "shift" a data into led matrix display ?
    By CuriousOne in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 9th January 2015, 17:09
  2. Replies: 0
    Last Post: - 14th November 2013, 04:32
  3. Overflows "counter" in a loop
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 11th September 2010, 10:26
  4. Replies: 2
    Last Post: - 22nd January 2008, 15:25
  5. LED "capacitance" won't get lower
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 3rd May 2007, 21:31

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