Quantcast
Channel: neophob.com
Viewing all articles
Browse latest Browse all 36

Espruino and WS2801

$
0
0

Here is a quick and ugly code to drive 50 WS2801 LED modules on a Espruino board:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var nrOfPixels = 50;
var rgb = new Uint8Array(nrOfPixels*3);

var k=0,jj=0;

SPI2.setup({baud:1000000, mosi:B15, sck:B13 });
USB.setup({baudrate:115200});
var serialBuffer = createRingBuffer(3);

function sendDataOut() {
  SPI2.send(rgb);
}


setInterval(function() {
    jj=k;
    for (var i=0;i<rgb.length;i+=3) {
      wheel(i, k++);
    }
    k=(jj+1)%255;
    sendDataOut();
  //}
}, 15);

console.log("init done");
           
Pin.prototype.startFlashing = function(period) {
  var me = this;
  var on = false;
  setInterval(function() {
    on = !on;
    digitalWrite(me, on);
  }, period);
};
LED3.startFlashing(500);

function wheel(ofs, pos) {
  pos %= 255;
  if (pos < 86) {
    Color(ofs, pos * 3, 255 - pos * 3, 0);
  }
  else if (pos < 171) {
    pos -= 85;
    Color(ofs, 255 - pos * 3, 0, pos * 3);
  }
  else {
    pos -= 170;
    Color(ofs, 0, pos * 3, 255 - pos * 3);
  }
}

function Color(ofs, r,g,b) {
  rgb[ofs] = r%255;
  rgb[ofs+1] = g%255;
  rgb[ofs+2] = b%255;
}

This sketch displays a simple rainbow pattern. I goal is a Espruino firmware for PixelController… we’ll see


Viewing all articles
Browse latest Browse all 36

Trending Articles