Experimental WS2812 driver and pixel buffer

Dependencies:   PixelArray WS2812 mbed

Committer:
chris
Date:
Mon Aug 18 13:55:20 2014 +0000
Revision:
2:57db905622ca
Parent:
1:bf4d674d3692
Code tidy

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 1:bf4d674d3692 10 DigitalOut led(LED1);
chris 1:bf4d674d3692 11
chris 0:6b847e039b3b 12 int main()
chris 0:6b847e039b3b 13 {
chris 0:6b847e039b3b 14
chris 0:6b847e039b3b 15 ws.useII(2); // use per-pixel intensity scaling
chris 0:6b847e039b3b 16
chris 0:6b847e039b3b 17 // set up the colours we want to draw with
chris 0:6b847e039b3b 18 int colorbuf[6] = {0x2f0000,0x2f2f00,0x002f00,0x002f2f,0x00002f,0x2f002f};
chris 0:6b847e039b3b 19
chris 1:bf4d674d3692 20 // for each of the colours (j) write out 10 of them
chris 2:57db905622ca 21 // the pixels are written at the colour*10, plus the colour position
chris 1:bf4d674d3692 22 // all modulus 60 so it wraps around
chris 1:bf4d674d3692 23 for (int i =0; i<6; i++) {
chris 1:bf4d674d3692 24 for (int j=0; j<10; j++) {
chris 2:57db905622ca 25 px.Set(((i*10)+j)%60,colorbuf[i]);
chris 0:6b847e039b3b 26 }
chris 0:6b847e039b3b 27 }
chris 1:bf4d674d3692 28
chris 2:57db905622ca 29 // now all the colours are computed, add a fade effect using intensity scaling
chris 1:bf4d674d3692 30 // compute and write the II value for each pixel
chris 1:bf4d674d3692 31 for (int j=0; j<60; j++) {
chris 1:bf4d674d3692 32 // px.SetI(pixel position, II value)
chris 2:57db905622ca 33 px.SetI(j%60, 0xf+(0xf*(j%10)));
chris 1:bf4d674d3692 34 }
chris 1:bf4d674d3692 35
chris 1:bf4d674d3692 36
chris 2:57db905622ca 37 // Now the buffer is written, rotate it
chris 2:57db905622ca 38 // by writing it out with an increasing offset
chris 1:bf4d674d3692 39 while (1) {
chris 1:bf4d674d3692 40 for (int z=59; z >= 0 ; z--) {
chris 2:57db905622ca 41 ws.write_offsets(px.getBuf(),z,z,z);
chris 1:bf4d674d3692 42 wait(0.075);
chris 1:bf4d674d3692 43 }
chris 1:bf4d674d3692 44 }
chris 1:bf4d674d3692 45
chris 0:6b847e039b3b 46 }