Debug changes but wants to publish back... making a fork...
Dependencies: PixelArray WS2812 mbed
Fork of ChrisRGB-Ring by
main.cpp@1:bf4d674d3692, 2014-08-18 (annotated)
- Committer:
- chris
- Date:
- Mon Aug 18 13:27:10 2014 +0000
- Revision:
- 1:bf4d674d3692
- Parent:
- 0:6b847e039b3b
- Child:
- 2:57db905622ca
Rotate buffer using offsets
Who changed what in which revision?
User | Revision | Line number | New 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 | 1:bf4d674d3692 | 15 | int ctr=0; |
chris | 0:6b847e039b3b | 16 | ws.useII(2); // use per-pixel intensity scaling |
chris | 0:6b847e039b3b | 17 | |
chris | 0:6b847e039b3b | 18 | // set up the colours we want to draw with |
chris | 0:6b847e039b3b | 19 | int colorbuf[6] = {0x2f0000,0x2f2f00,0x002f00,0x002f2f,0x00002f,0x2f002f}; |
chris | 0:6b847e039b3b | 20 | |
chris | 0:6b847e039b3b | 21 | |
chris | 1:bf4d674d3692 | 22 | int h=0; |
chris | 0:6b847e039b3b | 23 | |
chris | 1:bf4d674d3692 | 24 | // for each of the colours (j) write out 10 of them |
chris | 1:bf4d674d3692 | 25 | // the pixel get written at the rotation offset, plus the colour*10, plus the colour position |
chris | 1:bf4d674d3692 | 26 | // all modulus 60 so it wraps around |
chris | 1:bf4d674d3692 | 27 | for (int i =0; i<6; i++) { |
chris | 1:bf4d674d3692 | 28 | for (int j=0; j<10; j++) { |
chris | 1:bf4d674d3692 | 29 | px.Set((h+(i*10)+j)%60,colorbuf[i]); |
chris | 0:6b847e039b3b | 30 | } |
chris | 0:6b847e039b3b | 31 | } |
chris | 1:bf4d674d3692 | 32 | |
chris | 1:bf4d674d3692 | 33 | // now all the colours are computed, add a fade effect |
chris | 1:bf4d674d3692 | 34 | // compute and write the II value for each pixel |
chris | 1:bf4d674d3692 | 35 | for (int j=0; j<60; j++) { |
chris | 1:bf4d674d3692 | 36 | // px.SetI(pixel position, II value) |
chris | 1:bf4d674d3692 | 37 | px.SetI( (h+j)%60, 0xf+(0xf*(j%10))); |
chris | 1:bf4d674d3692 | 38 | } |
chris | 1:bf4d674d3692 | 39 | |
chris | 1:bf4d674d3692 | 40 | // the buffer is written |
chris | 1:bf4d674d3692 | 41 | // rotate by writing it out with an increasing offset |
chris | 1:bf4d674d3692 | 42 | |
chris | 1:bf4d674d3692 | 43 | |
chris | 1:bf4d674d3692 | 44 | while (1) { |
chris | 1:bf4d674d3692 | 45 | for (int z=59; z >= 0 ; z--) { |
chris | 1:bf4d674d3692 | 46 | ws.write_offsets(px.getBuf(),z,z,z); // write out the buffer |
chris | 1:bf4d674d3692 | 47 | wait(0.075); |
chris | 1:bf4d674d3692 | 48 | if (ctr==1000) { |
chris | 1:bf4d674d3692 | 49 | ctr=0; |
chris | 1:bf4d674d3692 | 50 | led=!led; |
chris | 1:bf4d674d3692 | 51 | } else { |
chris | 1:bf4d674d3692 | 52 | ctr++; |
chris | 1:bf4d674d3692 | 53 | } |
chris | 1:bf4d674d3692 | 54 | } |
chris | 1:bf4d674d3692 | 55 | } |
chris | 1:bf4d674d3692 | 56 | |
chris | 0:6b847e039b3b | 57 | } |