ambient.on('sound-trigger', function(data) {
    console.log('Something happened with sound: ', data);

    ambient.clearSoundTrigger();
    var anim = Buffer.concat(fadeIn(NEO_LENGTH, NUM_FRAMES * FRAME_MULTIPLIER));

    neo.on('end', function() {
      console.log((animCount++), ' ended');
      if (animCount === END_FADE_IN) {
        anim = Buffer.concat(steady(NEO_LENGTH, NUM_FRAMES));
      } else if (animCount === END_ANIMATION) {
        anim = Buffer.concat(fadeOut(NEO_LENGTH, NUM_FRAMES * FRAME_MULTIPLIER));
      }

      if (animCount < END_FADE_OUT) {
        neo.animate(NUM_FRAMES, anim);
      } else {
        ambient.setSoundTrigger(SOUND_LEVEL);
        animCount = 0;
      }
    });

    console.log('starting neopixel animation');
    neo.animate(NUM_FRAMES, anim);
  });
Beispiel #2
0
var NPS = require('neopixels');

var neo = new NPS();

var trace = Buffer.concat(tracer(600));
neo.on('end', function() {
  // Start the animation again
  neo.animate(60, trace);
});

function tracer(numLEDs) {
  var trail = 100;
  var arr = new Array(numLEDs);
  for (var i = 0; i < numLEDs; i++) {
    var buf = new Buffer(numLEDs * 3);
    buf.fill(0);
    for (var col = 0; col < 3; col++){
      for (var k = 0; k < trail; k++) {
        buf[(3*(i+numLEDs*col/3)+col+1 +3*k)] = (0xFF-(col * (0xFF/6)));
      }
    }
    arr[i] = buf;
  }
  return arr;
}

neo.animate(60, trace);
Beispiel #3
0
    // // here we are creating the color for each pixel
    // for (var col = 0; col < 3; col++){
    //     var bufnum = (3*(i+numLEDs*col/3)+col+1 +3*k);
	   //  var trailnum  = 0xFF*(trail-k)/trail;
	   //  // console.log('trailnum', bufnum, trailnum);
	   //  buf[col*i] = 255;
	   //  //buf[(3*(i+numLEDs*col/3)+col+1 +3*k)] =255;//0xFF*(trail-k)/trail;
	   //  console.log('a',buf[(3*(i+numLEDs*col/3)+col+1 +3*k)]);
    // }

    arr[i] = buf;
  }
  return arr;

}

neopixels.on('end', function() {
  neopixels.animate(60, Buffer.concat(tracer(60)));
});

// The first argument represents the number of lights (or pixels) we have
// The second argument is the data we are sending in
neopixels.animate(60, Buffer.concat(tracer(60)));

// each pixel is 3 bytes
// grb 
// send out an animation that is the number of pixels 60
// 60*3 = 180 bytes
// send over a buffer that is the 180 bytes and each frame of the animation 

//180 bytes to each frame 
Beispiel #4
0
var ambient = ambientlib.use(tessel.port['A']); 

var level0colorArray = new Array('','','','','','','','','');
var level1colorArray = new Array('red','orange','green','green','green','orange','green','green','green');
var level2colorArray = new Array('red','orange','orange','green','green','orange','orange','green','green');
var level3colorArray = new Array('red','red','orange','orange','green','red','orange','orange','green');
var level4colorArray = new Array('red','red','red','orange','orange','red','red','orange','orange');
var level5colorArray = new Array('red','red','red','red','red','red','red','red','red');


level(ledBuffer,0,level0colorArray);
neopixels.animate(nrOfLeds, ledBuffer);

neopixels.on('end', function() {
  neopixels.animate(nrOfLeds, ledBuffer);
});


ambient.on('ready', function () {
  // Get a stream of the data readings
  ambient.on('sound', function (lightData) {
    console.log('Light data, stream method: ' + lightData);
    for (var i =0; i < lightData.length;i++) {
    	var d = lightData[i];
    	if (d < 0.018) level(ledBuffer,0,level0colorArray);
		if (d < 0.04 && d > 0.018) level(ledBuffer,0,level1colorArray);
		if (d < 0.05 && d > 0.04) level(ledBuffer,0,level2colorArray);
		if (d < 0.08 && d > 0.05) level(ledBuffer,0,level3colorArray);
		if (d > 0.08 ) level(ledBuffer,0,level5colorArray);