Dimming Neopixels, Delays<Microseconds
Posted: Wed May 01, 2019 4:32 pm
Neopixels have great possibilties. With a normal LEDs you can show the state of a system (blue= too cold, red= too hot). With a neopixel you can show values in between with smoothly changing colors from for instance blue ... many colors ... red.
Dimming an LED may be done with PWM - not so with a Neopixel.
And Neopixels have crude timings. (400 ns)
Here is a very small RTOS-task dimming a Neopixel with different colors.
BTW It can be used for very short delays below 1 microsecond.
Have fun
Dimming an LED may be done with PWM - not so with a Neopixel.
And Neopixels have crude timings. (400 ns)
Here is a very small RTOS-task dimming a Neopixel with different colors.
BTW It can be used for very short delays below 1 microsecond.
Have fun
Code: Untitled.c Select all
// ----------- NeoPixel -------------
//---------- WS2812B.pdf ------------
inline void BitL(int lp) {
int ii;
gpio_set_level( RTOS_PinNeo, 0);
for (ii=0; ii<lp; ii++) {
asm(" nop");
}
}
inline void BitH(int lp) {
int ii;
gpio_set_level( RTOS_PinNeo, 1);
for (ii=0; ii<lp; ii++) {
asm(" nop");
}
}
inline void Bit1() {
BitH(21);
BitL(6); // 21/6 // from experiments
}
inline void Bit0() {
BitH(8);
BitL(20); // 8/20
}
inline void Color( uint32_t c) {
int i;
for (i=0;i<24;i++) {
if (c & 0x800000 ) Bit1();
else Bit0();
c<<=1;
}
}
/**
* \name NeoPix
* @{
* Dimming Blink of NeoPixel, 3 colors: red, green, blue
*
* \hideinitializer
*
*/
void NeoPix( void * pvParameters ) {
uint32_t c=0, cc=0;
int up=1;
unsigned int state=0;
gpio_set_direction(RTOS_PinNeo, GPIO_MODE_OUTPUT ); // Data-Pin of NeoPixel
c=0x01;
while(1) {
portDISABLE_INTERRUPTS();
Color(cc);
BitL(2);
//SentColors++; // for testing
// Dimming and blinking ...
if (up) { c+=1; if (c>=0xfe) up=0;}
else { c-=1; if (c==0x000000) { up=1; state+=8;} } // BRG: shift 0, 8, 16
if (state>16) state=0;
cc = (c<<state);
portENABLE_INTERRUPTS();
vTaskDelay(1);
}
}
// --- End NeoPixel
/** @} */