/**
 * 單顆 74hc595 跑馬燈
 * 
 * @link http://www.gibar.co/2016/01/linkit-7688-duo-74hc595-led.html
 */
var m = require('mraa');

// 腳位命名參考
//       _______
//  Q1[1|   U   |16]Vcc
//  Q2[2|       |15]Q0
//  Q3[3|       |14]DS
//  Q4[4|  595  |13]OE
//  Q5[5|       |12]STCP
//  Q6[6|       |11]SHCP
//  Q7[7|       |10]MR
// GND[8|_______| 9]Q7s
//       
var DS   = new m.Gpio(15),  
    STCP = new m.Gpio(16),
    SHCP = new m.Gpio(17);

// 設定為 output
DS  .dir(m.DIR_OUT);
STCP.dir(m.DIR_OUT);
SHCP.dir(m.DIR_OUT);

var valeurMirroir=0;

function setOutput(value) {
    valeurMirroir=value;
    for( var i = 0 ; i < 16 ; i++) {
      // Set data bit
      console.log("    value:" + (value & 0x8000) );
      if((value & 0x8000) == 0x8000)
          DS.write(1);
      else
          DS.write(0);
          
      // clock data
      SHCP.write(0);
      SHCP.write(1);
      value = value << 1;
     }
     // latch data
      STCP.write(1);
      STCP.write(0);
    }



function setBit(bitIndex) {
    console.log( "  setBit(" + bitIndex + "):" + (1 << bitIndex) );
  setOutput(valeurMirroir | (1 << bitIndex));
}

function clrBit(bitIndex) {
    console.log( "  clrBit(" + bitIndex + "):" + ~(1 << bitIndex) );
  setOutput(valeurMirroir & ~(1 << bitIndex));
}

var chaserIndex=0;

setInterval(function() {
  
   if(chaserIndex > 15){
     console.log("clear: " + chaserIndex + " -16");
     clrBit(chaserIndex - 16);
   }
   else {
     console.log("set bit:" + chaserIndex);
     setBit(chaserIndex);
       
   }
   chaserIndex++;
   if(chaserIndex > 31) 
     chaserIndex=0;
   },50);

@@ -19,16 +19,79 @@
 %E8%B7%91%E9%A6%AC%E7%87%88%0A * %0A
+ * @author Abola Lee %0A * @version 1.0%0A * @since 2016-01-09%0A * %0A
  * @link
@@ -671,18 +671,17 @@
 0 ; i %3C 
-16
+8
  ; i++) 
@@ -750,18 +750,16 @@
 e & 0x80
-00
 ) );%0A   
@@ -777,18 +777,16 @@
 e & 0x80
-00
 ) == 0x8
@@ -786,18 +786,16 @@
  == 0x80
-00
 )%0A      
@@ -1381,18 +1381,17 @@
 Index %3E 
-15
+7
 )%7B%0A     
@@ -1431,18 +1431,17 @@
 ex + %22 -
-16
+8
 %22);%0A    
@@ -1462,18 +1462,17 @@
 Index - 
-16
+8
 );%0A   %7D%0A
@@ -1606,10 +1606,10 @@
 x %3E 
-3
 1
+5
 ) %0A 

Update 8_led_squence.js