Author | Rob Hamerling, Copyright © 2014..2014, all rights reserved. |
Adapted-by | |
Compiler | 2.4q2 |
Library to control a chain of WS2812Bs This library uses the USART module with master SYNC protocol. - A PIC with Fosc of at least 32 MHz is required. - A high speed USART is required (BRG16 bit in BAUDCON). - The first or only USART interface is used and initialized automatically. - The DIN wire of the WS2812B must be connected to pin_RX/DT of the PIC, and this pin must be configured for digital I/O. Notes: - The pin_RX/DT may have to be configured with Peripheral Pin Select (PPS) or Alternate Pin Function (APFCON_RXDTSEL). -- The clock pin is not used. - AN EXTERNAL SIGNAL INVERTER CIRCUIT IS REQUIRED! - Initialize the interface with procedure ws2812b_sync_init(). - The number of WS2812Bs in the chain must be defined with a constant: const WS2812B_NUM = 30 -- for 30 chained WS2812Bs - The user program should contain 3 byte arrays of WS2812B_NUM bytes each, one for green, one for red, one for blue, e.g.: var byte agreen[WS2812B_NUM] var byte ared[WS2812B_NUM] var byte ablue[WS2812B_NUM] - Procedure ws2812b_refresh() is used to pass the current color settings to the WS2812B LEDs. - Procedure ws2812b_all_white() can be used to give all LEDs the same intensitiy white (or clear all leds with intensity 0) while keeping the color settings in the arrays unchanged.
- Warnings are temporary(?) commented out.
ws2812b_sync_init()
Title: Initialize the USART for Synchronous transmit at the required speed Input: (none)
_ws2812b_write_pixel(byte in green, byte in red, byte in blue)
Title: Transfer 3 color bytes to the WS2812B chain Input: Color intensities of green, red and blue (3 bytes) Notes: - Each WS2812B bit is represented by 3 USART bits: (WS2812B '0' = 0b100, WS2812B '1' = 0b110) The USART transfers least significant bit first. USART data polarity is negative (0-bit = high, 1-bit = low) An external circuit should invert the polarity.
_transfer_byte(byte in data)
Title: Transmit a byte (with 3 WS2812B 'bits') Input: Byte with 3 WS2812B bits in the form of 9 USART bits. The 9th bit is fixed 1, so only 8 bits need be passed. Notes: - We do not wait for completion immediately after a write, but wait for completion of the previous write before the next write! This allows to execute instructions during the transfer time to prepare for the transmission of the next byte.
12f1840 | 12f1840_ws2812b_sync.jal |
18f14k22 | 18f14k22_ws2812b_sync.jal |
18f25k22 | 18f25k22_ws2812b_sync.jal |