FullColorLED WS2812B clock

このエントリーをはてなブックマークに追加

NeoPixcel WS2812B has 12 full color LED.

Why don’t you create a clock with obniz?

Materials

obniz

Battery

NeoPixcel ( soldered three pins )

Program

Every seconds, led to be light on is calculated.
And We use WS2812B obniz.js parts library.

Program

<!-- HTML Example -->
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <script src="https://obniz.io/js/jquery-3.2.1.min.js"></script>
  <script src="https://unpkg.com/obniz@2.0.2/obniz.js" crossorigin="anonymous"></script>
</head>
<body>

<div id="obniz-debug"></div>
  

<script>
const obniz = new Obniz("OBNIZ_ID_HERE");
obniz.onconnect = async function () {

  const leds = obniz.wired("WS2812B", {gnd:2, vcc: 1, din: 0});
  
  let positions = [0,0,0];
  
  obniz.repeat(()=>{
    
    var date = new Date();
    positions[0] = date.getHours() % 12;
    positions[1] = parseInt(date.getMinutes() / 5);
    positions[2] = parseInt(date.getSeconds() / 5);
    
    updateLED();
    
    var ctx = obniz.display._ctx();
    ctx.fillStyle='#000'
    ctx.fillRect(0, 0, obniz.display.width, obniz.display.height);
    ctx.fillStyle='#FFF';
    ctx.strokeStyle='#FFF';
    obniz.display.font('Avenir', 50)
    obniz.display.pos(0,0);
    obniz.display.print(`${date.getHours()}:${date.getMinutes()}`)
    
  }, 1000);
  
  function updateLED() {
    let brightness = 20;
    
    let arr = [];
    for (let i=0; i<12; i++){
      arr.push([0, 0, 0]);
    }
    arr[positions[0]][0] = brightness;
    arr[positions[0]][1] = brightness;
    arr[positions[1]][1] = brightness;
    arr[positions[1]][2] = brightness;
    if ((new Date()).getSeconds()%2==0) {
        arr[positions[2]][0] = brightness;
        arr[positions[2]][1] = brightness;
        arr[positions[2]][2] = brightness;
    }
    
    arr.unshift(arr.splice(-1, 1)[0])
    
    leds.rgbs(arr);
  }

}

</script>
</body>
</html>

Run Now

The html will be opened to run a program.

You will Get in Few Days

Circuit for Starter “obniz Board” is available on Amazon and other online stores.
You can get it at below

Our products and resellers

Forum

Visit our developer’s forum to discuss and discover technologies.

Forum

Contact

Feel free to contact out support and technical team.

Contact us