Addressable RGB LED's & LED strips


Closed Thread
Results 1 to 25 of 25

Hybrid View

  1. #1
    Join Date
    Feb 2013
    Location
    Quebec, Canada
    Posts
    67


    Did you find this post helpful? Yes | No

    Default Re: Addressable RGB LED's & LED strips

    Made a few mistakes, sorry...

    Code:
    '****************************************************************
    '*  Name    : NeoPixel                                           
    '*  Author  : Michel Jasmin & The Signal Path dot com BLOG
    '*  Notice  : Ref: The Signal Path dot com BLOG
    '*          : Tutorial on Programming the NeoPixel (WS2812) RGB LEDs
    '*          : http://thesignalpath.com/blogs/2014/07/14/watcheditdeletetutorial-on-programming-the-neopixel-ws2812-rgb-leds-equipment-giveaway/
    '*  Date    : 2014-08-13                                           
    '*  Version : 1.0                                               
    '*  Notes   :                                                   
    '*          :                                                   
    '****************************************************************
    'PIC18F25K22 @40MHz
    
    #CONFIG
            __CONFIG    _CONFIG1H, _FOSC_HSHP_1H & _PLLCFG_OFF_1H & _PRICLKEN_ON_1H & _FCMEN_ON_1H & _IESO_ON_1H
            __CONFIG    _CONFIG2H, _WDTEN_OFF_2H
            __CONFIG    _CONFIG3H, _PBADEN_ON_3H & _CCP2MX_PORTB3_3H  & _MCLRE_EXTMCLR_3H
            __CONFIG    _CONFIG4L, _STVREN_OFF_4L & _LVP_OFF_4L & _XINST_OFF_4L
            __CONFIG    _CONFIG5L, _CP0_ON_5L & _CP1_ON_5L & _CP2_ON_5L & _CP3_ON_5L
            __CONFIG    _CONFIG5H, _CPB_ON_5H & _CPD_ON_5H
    #ENDCONFIG
    
    DEFINE OSC 40   
    DEFINE NO_CLRWDT 1  ' Don't waste cycles clearing WDT
    
    '------------ ALIAS -------------------------
    LedPin      VAR LATC.3
    NeoPin      VAR LATC.5
    
    '------------ Const -------------------------
    NEO_NUM     CON 60
    CR CON 13
    LF CON 10
    
    '------------ Variables -------------------------
    NeoGreen    VAR BYTE[NEO_NUM]
    NeoBlue     VAR BYTE[NEO_NUM]
    NeoRed      VAR BYTE[NEO_NUM]
    NeoPixel    VAR BYTE
    BitCount    VAR BYTE
    TempW       VAR WORD
    
    'Flags
    AppFlags    VAR BYTE
    DataBit     VAR AppFlags.0
    
    
    '------------------------  Initialization -------------------------------
    
    Clear   ' Clear RAM before entry
    
    TRISC.3 = 0 'Led Pin
    TRISC.5 = 0 'NeoPin
    TRISC.6 = 1 'TX1
    TRISC.7 = 1 'RX1
    
    'The serial port is used only for debugging purpose.
    RCSTA = $90   ' Enable serial port & continuous receive
    TXSTA = $24   ' Enable transmit, BRGH = 1
    SPBRG = 17    ' 9600 Baud @ 40 MHz -0.03%
    SPBRGH = 4
    BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
    
    PAUSE 100
    
    HSEROUT [CR,LF,CR,LF,"Test NeoPixel v 18",CR,LF]
    
    'Blink a LED just to say: Hello, I'm alive!
    LedPin = 0
    FOR TempW = 0 TO 4
        TOGGLE LedPin
        PAUSE 250
    NEXT
    LedPin = 0
    
    DataBit = 0
    GOSUB NeoInit
    
    '------------ Main program -------------------------
    Main:
    
        'For testing purpose:
        'DataBit = 1
        'GOSUB NeoBit
        'GOTO Main
    
        GOSUB NeoDraw
        GOSUB NeoRotate
        PAUSE 25
        GOTO Main
    
    END
    
    NeoBit:
        IF DataBit = 1 THEN
            '400ns pulse required
            NeoPin = 1
    
            '3 nop = 500ns @ 32MHz
            '2 nop = 376ns @ 32MHz
    
            '2 nop = 300ns @ 40MHz
            '3 nop = 400ns @ 40MHz
    
            ASM
                nop
                nop
                nop
            ENDASM
            NeoPin = 0
    
        ELSE
            '800ns pulse required
            NeoPin = 1
    
            '5 nop = 740ns @ 32MHz
            '6 nop = 880ns @ 32MHz
    
            '6 nop = 700ns @ 40MHz
            '7 nop = 800ns @ 40MHz
    
            ASM
                nop
                nop
                nop
                nop
                nop
                nop
                nop
            ENDASM
            NeoPin = 0
        ENDIF
    
        RETURN
    
    NeoInit:
        FOR NeoPixel = 0 TO (NEO_NUM - 1)
    
            IF NeoPixel < 10 THEN
                NeoGreen[NeoPixel] = 0
                NeoBlue[NeoPixel] = 0
                NeoRed[NeoPixel] = 64
    
            ELSEIF NeoPixel < 20 THEN
                NeoGreen[NeoPixel] = 0
                NeoBlue[NeoPixel] = 64
                NeoRed[NeoPixel] = 0
    
            ELSEIF NeoPixel < 30 THEN
                NeoGreen[NeoPixel] = 0
                NeoBlue[NeoPixel] = 64
                NeoRed[NeoPixel] = 64
    
            ELSEIF NeoPixel < 40 THEN
                NeoGreen[NeoPixel] = 64
                NeoBlue[NeoPixel] = 0
                NeoRed[NeoPixel] = 0
    
            ELSEIF NeoPixel < 50 THEN
                NeoGreen[NeoPixel] = 64
                NeoBlue[NeoPixel] = 0
                NeoRed[NeoPixel] = 64
            ELSE
                NeoGreen[NeoPixel] = 64
                NeoBlue[NeoPixel] = 64
                NeoRed[NeoPixel] = 0
            ENDIF
    
        NEXT
    
        RETURN
    
    NeoDraw:
        FOR NeoPixel = 0 TO (NEO_NUM + 1)
            TempW = (NeoPixel * 8)
    
            FOR BitCount = 7 TO 0 STEP -1
                DataBit = NeoGreen.0[TempW + BitCount]
                GOSUB NeoBit
            NEXT
    
            FOR BitCount = 7 TO 0 STEP -1
                DataBit = NeoRed.0[TempW + BitCount]
                GOSUB NeoBit
            NEXT
    
            FOR BitCount = 7 TO 0 STEP -1
                DataBit = NeoBlue.0[TempW + BitCount]
                GOSUB NeoBit
            NEXT
    
        NEXT
    
        NeoPin = 0
    
        RETURN
    
    NeoRotate:
        FOR NeoPixel = 0 TO (NEO_NUM - 1)
            NeoGreen[NeoPixel] = NeoGreen[NeoPixel + 1]
            NeoBlue[NeoPixel] = NeoBlue[NeoPixel + 1]
            NeoRed[NeoPixel] = NeoRed[NeoPixel + 1]
        NEXT
    
        NeoGreen[NEO_NUM - 1] = NeoGreen[0]
        NeoBlue[NEO_NUM - 1] = NeoBlue[0]
        NeoRed[NEO_NUM - 1] = NeoRed[0]
    
        RETURN

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


    Did you find this post helpful? Yes | No

    Default Re: Addressable RGB LED's & LED strips

    Ordered strip recently, will see how this code works

  3. #3
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: Addressable RGB LED's & LED strips

    Hey CuriousOne, Have a look at this thread.
    http://www.picbasic.co.uk/forum/showthread.php?t=19694
    Dave Purola,
    N8NTA
    EN82fn

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


    Did you find this post helpful? Yes | No

    Default Re: Addressable RGB LED's & LED strips

    Well, all this is way too complicated.

    I wanted something simple, to drive single rgb led via 1 pin

Similar Threads

  1. RGB led driver ic lpd6803
    By m_flfl in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 4th July 2012, 20:35
  2. RGB led driver ic lpd6803
    By m_flfl in forum General
    Replies: 0
    Last Post: - 29th May 2012, 19:49
  3. Free LED lights and LED strips
    By mistrip in forum Adverts
    Replies: 0
    Last Post: - 18th May 2012, 04:44
  4. RGB LED driver, Any comments?
    By paxmowa in forum Schematics
    Replies: 31
    Last Post: - 7th March 2012, 21:52
  5. RGB LED Matrix
    By ERIK in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 28th June 2008, 07:01

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