1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

twinkling LED Christmas Star

Discussion in 'Microcontrollers' started by MrDEB, Dec 8, 2017.

  1. MrDEB

    MrDEB Well-Known Member

    Joined:
    Apr 16, 2007
    Messages:
    4,576
    Likes:
    25
    I hasd 10 circuit boards made with the Christmas Star silk screened on them. These are my 2017 Christmas presents to friends.
    Experimented with blue Leds as well as white LEDs. The white are way to bright.
    Did some creative IMO experimentation with a random number and have an acceptable twinkle effect. While not perfect but it works.
    I have a photo diode to turn on at night but have yet to insert the parts. Next year I hope to add more LEDs using a pic with more pins or connecting two Leds per port pin. Yes it is a very basic On/Off code but it works and uses the KISS method. Will hopefully post a video later.
     
  2. JonSea

    JonSea Well-Known Member

    Joined:
    Oct 1, 2012
    Messages:
    1,560
    Likes:
    139
    Location:
    Seattle, WA
    You might consider editting your code a little before posting it. I always try to clean up the things I've commented out because they didn't work, remove routines I've carried over from other programs that aren't actually used, etc., to make the code as easy to read as possible.

    Ho, ho, ho.
     
  3. MrDEB

    MrDEB Well-Known Member

    Joined:
    Apr 16, 2007
    Messages:
    4,576
    Likes:
    25
    Thanks for the suggestion
    Ho Ho Ho Merry Christmas
     
  4. dave miyares

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    2
    Likes:
    -10


     
  5. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    5,159
    Likes:
    155
    Location:
    morristown,tn
    Why so hard
    They still make resistors.
    Code (text):

    {
    *****************************************************************************
    * Name : UNTITLED.BAS *
    * Author : [select VIEW...EDITOR OPTIONS] *
    * Notice : Copyright (c) 2017 [select VIEW...EDITOR OPTIONS] *
    * : All Rights Reserved *
    * Date : 3/13/2017 *
    * Version : 1.0 *
    * Notes : *
    * : *
    *****************************************************************************
    }
    {
    }
    DEVICE = 18F2221 ' Tell the compiler what chip we are using
    CLOCK = 8 ' Tell the compiler what we will be setting the clock to (Mhz)
    CONFIG MCLRE = OFF
    'CONFIG fOSC = INTIO67 ' Internal oscillator, IO on pins 6 and 7
    INCLUDE "INTOSC8.bas"
    'INCLUDE "InternalOscillator.bas"
    'INCLUDE "SetDigitalIO.bas"
    'CONFIG MCLRE = OFF
    INCLUDE "SetDigitalIO.bas"
    INCLUDE "ADC.bas"
    INCLUDE "convert.bas"
    INCLUDE "Utils.bas"
    INCLUDE "RandGen.bas"
    // Read the AD ports and scale for the cds

    'FUNCTION Dsired_T() AS WORD //Dsired-T is speed selection
    ' result = (ADC.Read(0) +1)*500 /1024 //Read DESIRED TEMP Adjustment vis ADC
    'END FUNCTION


    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    DIM time AS WORD
    DIM pressed AS BYTE
    DIM x AS BYTE
    DIM y AS BYTE
    'DIM led0 AS PORTa.0 //ADC input
    DIM LED1 AS porta.1
    DIM LED2 AS PORTa.2
    DIM led3 AS porta.3
    DIM led4 AS PORTa.4
    DIM LED5 AS porta.5
    DIM LED6 AS PORTa.6
    DIM LED7 AS PORTa.7
    DIM led8 AS portb.0
    DIM led9 AS portb.1
    DIM led10 AS portb.2
    DIM led11 AS portb.3
    DIM led12 AS portb.4
    DIM led13 AS portb.5
    DIM led14 AS portb.6
    DIM led15 AS portb.7
    DIM led16 AS portc.0
    DIM led17 AS portc.1
    DIM led18 AS portc.2
    DIM led19 AS portc.3
    DIM led20 AS portc.4
    DIM led21 AS portc.5
    DIM led22 AS portc.6
    DIM led23 AS portc.7
    'DIM led16 AS portc.4
    DIM ms AS WORD
    DIM us AS WORD
    DIM RandomVal AS BYTE
    DIM Et AS BYTE
    // sub routines
    'OUTPUT (led0)
    OUTPUT (LED1)
    OUTPUT (LED2)
    OUTPUT (led3)
    OUTPUT (led4)
    OUTPUT (LED5)
    OUTPUT (LED6)
    OUTPUT (LED7)
    OUTPUT (led8)
    OUTPUT (led9)
    OUTPUT (led10)
    OUTPUT (led11)
    OUTPUT (led12)
    OUTPUT (led13)
    OUTPUT (led14)
    OUTPUT (led15)
    OUTPUT (led16)
    OUTPUT (led17)
    OUTPUT (led18)
    OUTPUT (led19)
    OUTPUT (led20)
    OUTPUT (led21)
    OUTPUT (led22)
    OUTPUT (led23)
    'led0 =0
    LED1 =0
    LED2 =0
    led3 =0
    led4 =0
    LED5 =0
    LED6 =0
    LED7 =0
    led8 =0
    led9 =0
    led10 =0
    led11=0
    led12 =0
    led13=0
    led14=0
    led15=0
    led16 =0
    led17 =0
    led18 =0
    led19=0
    led20=0
    led21 =0
    led22=0
    led23 =0
    'time = 10
    time = 20
    Et = 25 //15
    x = 0
    RandGen.Initialize(128) // Initialize the Random Number generator
    setalldigital
    // main program...
    // Vairy the time to flicker the leds
    WHILE true
    RandomVal= RandGen.Rand // Grab a random number from 0 to 255
    LED1=1
    LED2=1
    led3=1
    led4=1
    LED5=1
    LED6=1
    LED7=1
    led8=1
    led9=1
    led10=1
    led11=1
    led12=1
    led13=1
    led14=1
    led15=1
    led16=1
    led17=1
    led18=1
    led19=1
    led20=1
    led21=1
    led22=1
    led23=1
    time= RandGen.Rand // Grab a random number from 0 to 255


    SELECT time
    CASE >244 TOGGLE (LED1)DELAYMS(Et) //
    CASE >233 TOGGLE (led23)DELAYMS(Et)//
    CASE >222 TOGGLE (led20)DELAYMS(Et)//
    CASE >211 TOGGLE (led4)DELAYMS(Et) //
    CASE >200 TOGGLE (led15)DELAYMS(Et) //
    CASE >189 TOGGLE (led16)DELAYMS(Et) //
    CASE >178 TOGGLE (LED2)DELAYMS(Et) //
    CASE >167 TOGGLE (led8)DELAYMS(Et) //
    CASE >156 TOGGLE (led19)DELAYMS(Et) //
    CASE >145 TOGGLE (led10)DELAYMS(Et) //
    CASE >134 TOGGLE (led11)DELAYMS(Et) //
    CASE >123 TOGGLE (led3)DELAYMS(Et) //
    CASE >112 TOGGLE (led13)DELAYMS(Et) //
    CASE >101 TOGGLE (led14)DELAYMS(Et) //
    CASE >90 TOGGLE (LED5)DELAYMS(Et) //
    CASE >79 TOGGLE (led9)DELAYMS(Et)
    CASE >68 TOGGLE (led17)DELAYMS(Et) //
    CASE >57 TOGGLE (led12)DELAYMS(Et)//
    CASE >46 TOGGLE (led9)DELAYMS(Et) //
    CASE >35 TOGGLE (led18)DELAYMS(Et)//
    CASE >24 TOGGLE (LED6)DELAYMS(Et) //
    CASE >13 TOGGLE (led21)DELAYMS(Et)//
    CASE >1 TOGGLE (LED7)DELAYMS(Et) //

    END SELECT

    WEND
    {
     
     
  6. MrDEB

    MrDEB Well-Known Member

    Joined:
    Apr 16, 2007
    Messages:
    4,576
    Likes:
    25
    I should have used bigger resistors for the white LEDs. Learn by our mistakes.
    I had fun writing the code if it makes any difference. The learn by doing method.
    Keep warm Bert, I hear tell you got snow in the south? It is in the low 20's here in Washington
     

Share This Page