Menu

Christmas: LED Candle Simulator!!

Anobium
2017-12-19
2017-12-21
  • Moto Geek

    Moto Geek - 2017-12-19

    I did something similar a couple of years ago and just dug up the code. I can't remember if it worked well, but I kept the code, so maybe... I will have to wire one up to test and also try your code as well. Fun stuff!!!

    #chip 12f1840,32
    
    Dir PORTA.2 out
    Dir PORTA.4 In
    
    start:
    randomize ReadAD(AN3)
    tt = random
    dd = random
    
    for j = 50 to dd step 2
    hpwm 1, 5, j
    wait tt 10us
    next j
    
    for j = dd to 50 step -2
    hpwm 1, 5, j
    wait tt 10us
    next j
    
    goto start
    
     
    • Anobium

      Anobium - 2017-12-19

      Like it - works very nicely! Uses CCP1/PWM clever but does need the CCP module.

       
  • Moto Geek

    Moto Geek - 2017-12-19

    Just found another one from the way back section of my server. If I remember right, I had a big led that wasn't responding to the pwm like a normal led, so a kind sole in the forum had a different (slower) pwm library that I may have used here. Not exactly sure right now. Have to hook things back up and try them out... I also think I found this routine somewhere and modified it for GCB.

    #chip 12f1840,32
    
    #DEFINE LED PORTA.2
    DIR PORTA.2 out
    
    Dir PORTA.1 In
    randomize ReadAD(AN1)
    
    
     #define flicker_low_min 120
     #define flicker_low_max 160
    
     #define flicker_high_min 230
     #define flicker_high_max 255
    
     #define flicker_hold_min 40
     #define flicker_hold_max 80
    
     #define flicker_pause_min 20
     #define flicker_pause_max 155
    
     #define flicker_speed_min 5
     #define flicker_speed_max 200
    
    
     flicker_random_low_start = 0
     flicker_random_low_end = 0
     flicker_random_high = 0
     flicker_random_speed_start = 0
     flicker_random_speed_end = 0
    
     do
        for pp = 1 to 10
        'random time for low
        flicker_random_low_start = rolldice(flicker_low_min, flicker_low_max)
        flicker_random_low_end = rolldice(flicker_low_min, flicker_low_max)
    
       'random time for high
        flicker_random_high = rolldice(flicker_high_min, flicker_high_max)
    
        'random time for speed
        flicker_random_speed_start = rolldice(flicker_speed_min, flicker_speed_max)
        flicker_random_speed_end = rolldice(flicker_speed_min, flicker_speed_max)
    
        'low -> high
         for nn = flicker_random_low_start to flicker_random_high
         hpwm 1, 16, nn
         wait flicker_random_speed_start 10us
         next nn
    
    
         'hold
        wait rolldice(flicker_hold_min, flicker_hold_max) ms
    
         'high -> low
        for nn = flicker_random_high to flicker_random_low_end step -1
        hpwm 1, 16, nn
        wait flicker_random_speed_end 10us
        next nn
    
        wait rolldice(flicker_pause_min, flicker_pause_max) ms
    
        next pp
    loop
    
    
    function rolldice(minval, maxval)
    rn = Random
    aa = maxval - minval + 1
    bb = rn mod aa
    rolldice = minval + bb
    end function
    
     

    Last edit: Moto Geek 2017-12-21
    • Anobium

      Anobium - 2017-12-19

      NICE! Love the dice function! This has more of random flicker!

      Also, looks very nice on the scope!

      Santa is coming!

       

      Last edit: Anobium 2017-12-19
  • Moto Geek

    Moto Geek - 2017-12-19

    I use the rolldice function quite a bit for led fun and other things.

     
    • Anobium

      Anobium - 2017-12-19

      Lotto winning tickets!

       
  • Moto Geek

    Moto Geek - 2017-12-19

    So far, just lotto tickets. No winners yet. But if it happens, I will definetly give GCB ALL the credit.

     
  • jackjames

    jackjames - 2017-12-21

    Sorry for my english.
    This is the adaptation of a program I had written in another language to generate the flame of 8 candles with independent flicker.
    The delay in milliseconds should be chosen based on the desired effect.
    With this circuit I turn on the candles consisting of incandescent microlamps but I think that with the LEDs it goes well.

     
    • Anobium

      Anobium - 2017-12-21

      @jackjames

      Crazy LEDs!! Look pretty - I got four LEDs operating on a PicKit2 Low Pin Count Board.

      :-)

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.