Experimental WS2812 driver and pixel buffer

Dependencies:   PixelArray WS2812 mbed

Committer:
chris
Date:
Wed Aug 06 09:34:24 2014 +0000
Revision:
0:6b847e039b3b
Child:
1:bf4d674d3692
First commit and publish;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chris 0:6b847e039b3b 1 #include "mbed.h"
chris 0:6b847e039b3b 2 #include "WS2812.h"
chris 0:6b847e039b3b 3 #include "PixelArray.h"
chris 0:6b847e039b3b 4
chris 0:6b847e039b3b 5 #define WS2812_BUF 60
chris 0:6b847e039b3b 6
chris 0:6b847e039b3b 7 WS2812 ws(p5,WS2812_BUF);
chris 0:6b847e039b3b 8 PixelArray px(WS2812_BUF);
chris 0:6b847e039b3b 9
chris 0:6b847e039b3b 10 int main()
chris 0:6b847e039b3b 11 {
chris 0:6b847e039b3b 12
chris 0:6b847e039b3b 13 ws.useII(2); // use per-pixel intensity scaling
chris 0:6b847e039b3b 14
chris 0:6b847e039b3b 15 // set up the colours we want to draw with
chris 0:6b847e039b3b 16 int colorbuf[6] = {0x2f0000,0x2f2f00,0x002f00,0x002f2f,0x00002f,0x2f002f};
chris 0:6b847e039b3b 17
chris 0:6b847e039b3b 18 while(1) {
chris 0:6b847e039b3b 19
chris 0:6b847e039b3b 20 // h is the starting point, incrementing makes the rendered buffer rotate
chris 0:6b847e039b3b 21 for (int h=0; h<60; h++) {
chris 0:6b847e039b3b 22
chris 0:6b847e039b3b 23 // for each of the colours (j) write out 10 of them
chris 0:6b847e039b3b 24 // the pixel get written at the rotation offset, plus the colour*10, plus the colour position
chris 0:6b847e039b3b 25 // all modulus 60 so it wraps around
chris 0:6b847e039b3b 26 for (int i =0; i<6; i++) {
chris 0:6b847e039b3b 27 for (int j=0; j<10; j++) {
chris 0:6b847e039b3b 28 px.Set((h+(i*10)+j)%60,colorbuf[i]);
chris 0:6b847e039b3b 29 }
chris 0:6b847e039b3b 30 }
chris 0:6b847e039b3b 31
chris 0:6b847e039b3b 32 // now all the colours are computed, add a fade effect
chris 0:6b847e039b3b 33 // compute and write the II value for each pixel
chris 0:6b847e039b3b 34 for (int j=0; j<60; j++) {
chris 0:6b847e039b3b 35 // px.SetI(pixel position, II value)
chris 0:6b847e039b3b 36 px.SetI( (h+j)%60, 0xf+(0xf*(j%10)));
chris 0:6b847e039b3b 37 }
chris 0:6b847e039b3b 38
chris 0:6b847e039b3b 39 ws.write(px.getBuf()); // write out the buffer
chris 0:6b847e039b3b 40 wait(0.05);
chris 0:6b847e039b3b 41 }
chris 0:6b847e039b3b 42 }
chris 0:6b847e039b3b 43 }