WS2812 Driver - No need for dedicated cog
DavidZemon
Posts: 2,973
First, a hat tip to JohnnyMac's original WS2812 driver. It's been copied numerous times and I'm incrementing that counter one more.
For anyone who would like to use the WS2812 series of LEDs but doesn't have a spare cog, PropWare now has an object for you. I mention this outside the PropWare thread because I suspect even a beginner would have very little trouble removing the couple PropWare-specific lines of code and replacing them with generic Propeller lines.
https://github.com/DavidZemon/PropWare/blob/release-2.0-nightly/PropWare/ws2812.h
And if the link dies, I've also attached a snapshot
A short example program that fades from black to (dim) white and back in an endless loop:
For anyone who would like to use the WS2812 series of LEDs but doesn't have a spare cog, PropWare now has an object for you. I mention this outside the PropWare thread because I suspect even a beginner would have very little trouble removing the couple PropWare-specific lines of code and replacing them with generic Propeller lines.
https://github.com/DavidZemon/PropWare/blob/release-2.0-nightly/PropWare/ws2812.h
And if the link dies, I've also attached a snapshot
A short example program that fades from black to (dim) white and back in an endless loop:
#include "PropWare/ws2812.h" const PropWare::Pin::Mask LED_TX_PIN_MASK = PropWare::Pin::P27; int main () { const PropWare::WS2812 led(LED_TX_PIN_MASK, PropWare::WS2812::GRB); const int delay = 40 * MILLISECOND; while (1) { unsigned int i; // Go bright for (i = 0; i < 0x101010; i += 0x010101) { led.send(i); waitcnt(delay + CNT); } // Go dim for (; i; i -= 0x010101) { led.send(i); waitcnt(delay + CNT); } } }