Menu

Smart Seriel RGB LED

Help
2016-06-29
2016-08-17
  • Macgman2000

    Macgman2000 - 2016-06-29

    Hello,

    I am looking for a library or sample code for controlling a string of serial RGB LEDS. I would appreciate the help!

    It uses a type of manchester code per bit. WS2812 sold on Adafruit.

    Thanks!
    Nick

     

    Last edit: Macgman2000 2016-06-29
  • Anobium

    Anobium - 2016-06-30

    Hi Nick and welcome,

    This is essentially an SPI device. This means you send a stream of three bytes to control the color and a small wait to allow the chip to process the bytes.

    There is a lot of example code on the internet and converting to Great Cow BASIC is not a challenge.

    What level of coder are you?
    Which microcontroller are you planning to use?
    Is the only device you plan to connect to the microcontroller ?
    And, have you seen some code or a Youtube video that shows what the end goal should be?

    Anobium

     
    • Macgman2000

      Macgman2000 - 2016-06-30

      Hi Anobium,

      Thanks for the response. I am just starting out on the Arduino Uno. Basically I want to vary the colors in a loop going through different fades and mixes. Nothing really in mind other than learning how to do it. Any code reference for SPI I should look at?

      Thanks!
      Nick

       
  • Anobium

    Anobium - 2016-06-30

    Your code needs to look something like this. This is not tested - so, your task is to decompose and make it work. :-)

    Lookup in the Help SPIMODE and SPITransfer, also,
    Look at the demos for a demo program called \GreatCowBasic\Demos\SPI Digital Pot Solutions\MCP4xxx SPI Pot\MCP4141_HardwareSPI_SimpleDemo_mega328p@16.gcb this has the same chip and working code for an SPI solution.

    Do not hestitate to ask questions.

    I hope this get you started.

    Anobium

    PS. When you get it going... I want the program back to publish as an demo!!

    :-)

    ~~~~~

    '''A program for GCGB and GCB.
    '''
    '''@author
    '''@licence GPL
    '''@version
    '''@date
    '''**************

    ; ----- Configuration
    #chip mega328p, 16
    #include <uno_mega328p.h></uno_mega328p.h>

    ; ----- Constants
    ' Four ports are required for HW SPI but we are only use two - data out and clock lines
    ' #define WS2812_CS DIGITAL_10
    #define WS2812_SCK DIGITAL_13
    #define WS2812_DO DIGITAL_11
    ' #define WS2812_DI DIGITAL_12

    ' Define Colors
    #define WS2812_BLACK   0x000000
    #define WS2812_RED     0xFF0000
    #define WS2812_GREEN   0x00FF00
    #define WS2812_BLUE    0x0000FF
    #define WS2812_WHITE   0xFFFFFF
    

    ; ----- Define Hardware settings
    ' None
    ; ----- Variables
    dim loopx as word

    'We use the lower three bytes to hold the color
    dim WS2812color as long
    

    ; ------ Start of main Program

    'Required to initialise the device
    WS2812Init
    

    ; ----- Example code

        do Forever
    
            WS2812WriteLEDs ( WS2812_RED , 1 )
            wait 500 ms
    
            WS2812WriteLEDs ( WS2812_GREEN , 1 )
            wait 500 ms
    
            WS2812WriteLEDs ( WS2812_WHITE , 1 )
            wait 500 ms
    
        Loop
    

    Sub WS2812Init
    SPIMode MasterFast, 0

      ' Four ports are required for HW SPI but we are only use two - data out and clock lines
    

    ' Dir WS2812_DI in
    Dir WS2812_DO Out
    Dir WS2812_SCK Out
    ' Dir WS2812_CS out

      ' Initial state of ports required for SW SPI
      set WS2812_DO off
      set WS2812_SCK off
    

    End Sub

    Sub WS2812WriteLEDs ( in LEDValue as long, in NumberofLEDs )

      'Send start frame
      SPITransfer ( 0x00, temp )
      SPITransfer ( 0x00, temp )
      SPITransfer ( 0x00, temp )
      SPITransfer ( 0x00, temp )
    
    
      for loopx = 0 to (NumberofLEDs+NumberofLEDs+NumberofLEDs) step 3
    
          'Maximum global brightness
          SPITransfer( 0xff, temp )
          SPITransfer( LEDValue, temp )                 'lower byte
          SPITransfer( LEDValue_H, temp )               'next byte
          SPITransfer( LEDValue_U, temp )               'last byte
    
      Next
    
    
      'End Frame
      loopx = 0
      do while loopx < NumberofLEDs
    
          'Send 8 more clock cycles
          SPITransfer( 0xff, temp )
          loopx = loopx + 16
    
      loop
    

    End Sub

     
    • Macgman2000

      Macgman2000 - 2016-06-30

      Thanks for the starter code :) I will post back when I get things sorted.

      Nick

       
    • Anobium

      Anobium - 2016-08-17

      THIS POSTING/CODE HAS BEEN SUPERCEDED. PLEASE LOOK AT THE DEMONSTRATIONS FOR WORKING CODE.

       

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.