Menu

Flash six LEDs repeatably in sequence

Anobium
2022-04-26
2022-04-26
  • Anobium

    Anobium - 2022-04-26

    I wrote this little demo when I was sent two of these ... - a little PCB with six LEDS. All very nice.

    So, the demo below - is this the smallest program to make the six LEDs flash repeatably in sequence?

    :-)

    #CHIP mega328p, 16
    #OPTION EXPLICIT
    
        //! Set the port as an output
        DIR PORTB OUT
        //! Set the LED on
        PORTB.5 = 1
    
        //! Loop for ever    
        do
    
            //! Rotate to shift the port values to the right.  We use the carry bit to reset the sequence
            ROTATE PORTB RIGHT
    
            //! Set the port.bit to the value of C.  This will only be 1 when the portb.0 is shifted to the carry by the ROTATE
            PORTB.5 = C
    
            //! Wait 100 ms
            Wait 100 ms
    
        loop
    
    #CHIP LGT8F328P
    #OPTION EXPLICIT
    
        //! Set the port as an output
        DIR PORTB OUT
        //! Set the LED on
        PORTB.5 = 1
    
        //! Loop for ever    
        do
    
            //! Rotate to shift the port values to the right.  We use the carry bit to reset the sequence
            ROTATE PORTB RIGHT
    
            //! Set the port.bit to the value of C.  This will only be 1 when the portb.0 is shifted to the carry by the ROTATE
            PORTB.5 = C
    
            //! Wait 100 ms
            Wait 100 ms
    
        loop
    
     

    Last edit: Anobium 2022-04-26
  • stan cartwright

    stan cartwright - 2022-04-26

    This assembles !!!???
    takes 24 words prog mem, yours takes 40 words :)

    #CHIP mega328p, 16
    #OPTION EXPLICIT
    
        //! Set the port as an output
        DIR PORTB OUT
        PORTB=1
        do
        portb=portb+portb
        if portb=64 then portb=1
        wait 100 ms
        loop
    

    Edit it now takes 44 words ?? using gcstudio.
    see image... should have saved the first compile image.

     

    Last edit: stan cartwright 2022-04-26
  • Anobium

    Anobium - 2022-04-26

    Stan .. very good!

    I happended to have an LGT attached..

    #CHIP LGT8F328P
    #OPTION EXPLICIT
    
        //! Set the port as an output
        DIR PORTB OUT
    
        //! Set the initial value
        PORTB=1
    
        do
            //! Add the existing value of the port to the port... so, this doubles the port value
            PORTB=PORTB+PORTB
    
            //! If bit 6 is 1 then restart
            if PORTB = 64 then PORTB=1
    
            //! wait...
            wait 100 ms
        loop
    

    I just uploaded to GitHub! https://github.com/GreatCowBASIC/Demonstration_Sources/tree/main/LED_Solutions/LED_flash_in_sequence

     

    Last edit: Anobium 2022-04-26
  • stan cartwright

    stan cartwright - 2022-04-26

    @Anobium, your rotate method is a more ubiquitous solution for rotating 6 leds.
    my code doesn't fit in with existing style.. too simple.

     

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.