
Experimental WS2812 driver and pixel buffer
Dependencies: PixelArray WS2812 mbed
main.cpp
00001 #include "mbed.h" 00002 #include "WS2812.h" 00003 #include "PixelArray.h" 00004 00005 #define WS2812_BUF 60 00006 00007 WS2812 ws(p5,WS2812_BUF); 00008 PixelArray px(WS2812_BUF); 00009 00010 DigitalOut led(LED1); 00011 00012 int main() 00013 { 00014 00015 ws.useII(2); // use per-pixel intensity scaling 00016 00017 // set up the colours we want to draw with 00018 int colorbuf[6] = {0x2f0000,0x2f2f00,0x002f00,0x002f2f,0x00002f,0x2f002f}; 00019 00020 // for each of the colours (j) write out 10 of them 00021 // the pixels are written at the colour*10, plus the colour position 00022 // all modulus 60 so it wraps around 00023 for (int i =0; i<6; i++) { 00024 for (int j=0; j<10; j++) { 00025 px.Set(((i*10)+j)%60,colorbuf[i]); 00026 } 00027 } 00028 00029 // now all the colours are computed, add a fade effect using intensity scaling 00030 // compute and write the II value for each pixel 00031 for (int j=0; j<60; j++) { 00032 // px.SetI(pixel position, II value) 00033 px.SetI(j%60, 0xf+(0xf*(j%10))); 00034 } 00035 00036 00037 // Now the buffer is written, rotate it 00038 // by writing it out with an increasing offset 00039 while (1) { 00040 for (int z=59; z >= 0 ; z--) { 00041 ws.write_offsets(px.getBuf(),z,z,z); 00042 wait(0.075); 00043 } 00044 } 00045 00046 }
Generated on Tue Jul 19 2022 15:02:05 by
