59 CHARTREUSE = 0x7FFF00,
61 AQUAMARINE = 0x7FFFD4,
82 static unsigned int to_color (
const unsigned int red,
const unsigned int green,
const unsigned int blue) {
83 return ((red) << 16) | ((green) << 8) | (blue);
86 static unsigned int scale (
const unsigned int x,
const unsigned int l) {
90 static unsigned int colorx (
const unsigned int red,
const unsigned int green,
const unsigned int blue,
91 const unsigned int l) {
92 return (scale(red, l) << 16) | (scale(green, l) << 8) | scale(blue, l);
113 void send (
const unsigned int color)
const {
123 void send_array (
const unsigned int *buffer,
const size_t length)
const {
126 const unsigned int LONG_PULSE_WIDTH = (900 * MICROSECOND / 1000);
127 const unsigned int SHORT_PULSE_WIDTH = (350 * MICROSECOND / 1000);
128 const unsigned int RESET_DELAY = (50 * MICROSECOND);
130 unsigned int clock = RESET_DELAY;
133 unsigned int colorbits = 0;
134 unsigned int bitCounter = 0;
137 " fcache #(Ws2812End - Ws2812Start) \n\t" 138 " .compress off \n\t" 141 " add %[_clock], CNT \n\t" 142 " waitcnt %[_clock], #0 \n\t" 146 " rdlong %[_colorbits], %[_nextLed] \n\t" 147 " add %[_nextLed], #4 \n\t" 150 " tjz %[_swaprg], #__LMM_FCACHE_START+(shift_out%= - Ws2812Start) \n\t" 151 " mov %[_t1], %[_colorbits] \n\t" 152 " mov %[_t2], %[_colorbits] \n\t" 153 " and %[_colorbits], #0xff \n\t" 154 " shr %[_t1], #8 \n\t" 155 " and %[_t1], %[_byte1] \n\t" 156 " or %[_colorbits], %[_t1] \n\t" 157 " shl %[_t2], #8 \n\t" 158 " and %[_t2], %[_byte2] \n\t" 159 " or %[_colorbits], %[_t2] \n\t" 162 " shl %[_colorbits], #8 \n\t" 163 " mov %[_bitCounter], #24 \n\t" 165 "shift_out.loop%=: \n\t" 166 " rcl %[_colorbits], #1 wc \n\t" 167 " if_c mov %[_clock], %[_longPulse] ' bit1hi \n\t" 168 " if_nc mov %[_clock], %[_shortPulse] ' bit0hi \n\t" 169 " or OUTA, %[_pinMask] \n\t" 170 " add %[_clock], CNT \n\t" 171 " if_c waitcnt %[_clock], %[_shortPulse] ' bit1lo \n\t" 172 " if_nc waitcnt %[_clock], %[_longPulse] ' bit0lo \n\t" 173 " andn OUTA, %[_pinMask] \n\t" 174 " waitcnt %[_clock], #0 \n\t" 175 " djnz %[_bitCounter], #__LMM_FCACHE_START+(shift_out.loop%= - Ws2812Start) \n\t" 176 " djnz %[_nleds], #__LMM_FCACHE_START+(frame_loop%= - Ws2812Start) \n\t" 178 " jmp __LMM_RET \n\t" 180 " .compress default \n\t" 181 : [_clock]
"+r"(clock),
184 [_colorbits]
"+r"(colorbits),
185 [_bitCounter]
"+r"(bitCounter),
186 [_nextLed]
"+r"(buffer)
187 : [_pinMask]
"r"(this->m_pin.get_mask()),
188 [_nleds]
"r"(length),
189 [_swaprg]
"r"(this->m_type),
190 [_byte1]
"r"(BYTE_1),
191 [_byte2]
"r"(BYTE_2),
192 [_shortPulse]
"r"(SHORT_PULSE_WIDTH),
193 [_longPulse]
"r"(LONG_PULSE_WIDTH),
194 [_resetDelay]
"r"(RESET_DELAY));
197 uint32_t wheel (
unsigned int position) {
198 uint32_t resultingColor;
205 resultingColor =
to_color(255 - position * 3, position * 3, 0);
208 else if (position < 170) {
210 resultingColor =
to_color(0, 255 - position * 3, position * 3);
215 resultingColor =
to_color(position * 3, 0, 255 - position * 3);
218 return resultingColor;
221 uint32_t wheel_dim (
unsigned int position,
unsigned int brightness) {
229 color = colorx(255 - position * 3, position * 3, 0, brightness);
232 else if (position < 170) {
234 color = colorx(0, 255 - position * 3, position * 3, brightness);
240 color = colorx(position * 3, 0, 255 - position * 3, brightness);
void set_mask(const PropWare::Port::Mask mask)
Utility class to handle general purpose I/O pins.
void clear() const
Clear selected output port (set it to 0)
Generic definitions and functions for the Parallax Propeller.
static unsigned int to_color(const unsigned int red, const unsigned int green, const unsigned int blue)
Convert RGB values to a color code.
Type
Support both types of multicolor LEDs, RGB and GRB.
void send(const unsigned int color) const
Send a given color to the first LED in line.
void set_dir_out() const
Set the port for output.
An easy-to-use, cheap, small, and bright multicolor LED capable of being strung together in a lengthy...
WS2812(const Pin::Mask pinMask, const Type type)
Construct an instance connected to the given output line.
Color
Provide some common color codes.
Type get_type() const
Obtain the currently set RGB/GRB type.
void send_array(const unsigned int *buffer, const size_t length) const
Send a series of colors to a series of LEDs.