Ejemplo n.º 1
0
function doinit(){
	
	ws2812x.init(NUM_LEDS);
	ws2812x.setBrightness(brightness);
	
	ws2812x.reset();
	
	
	runLEDs();
	
}
Ejemplo n.º 2
0
Archivo: server.js Proyecto: peel/multi
function blink(){
  var NUM_LEDS = parseInt(process.argv[2], 10) || 8,
      pixelData = new Uint32Array(NUM_LEDS);
  var brightness = 128;

  ws281x.init(NUM_LEDS);

  var lightsOff = function () {
    for (var i = 0; i < NUM_LEDS; i++) {
      pixelData[i] = color(0, 0, 0);
    }
    ws281x.render(pixelData);
    ws281x.reset();
  };

  // ---- animation-loop
  var offset = 0;
  var times = 0;
  var animation = setInterval(function () {
      for (var i = 0; i < NUM_LEDS; i++) {
          pixelData[i] = wheel(((i * 256 / NUM_LEDS) + offset) % 256);
      }

      offset = (offset + 1) % 256;
      ws281x.render(pixelData);
      if (++times === 64) {
          clearInterval(animation);
          lightsOff();
      }
  }, 1000 / 30);

  // generate rainbow colors accross 0-255 positions.
  function wheel(pos) {
    pos = 255 - pos;
    if (pos < 85) { return color(255 - pos * 3, 0, pos * 3); }
    else if (pos < 170) { pos -= 85; return color(0, pos * 3, 255 - pos * 3); }
    else { pos -= 170; return color(pos * 3, 255 - pos * 3, 0); }
  }

  // generate integer from RGB value
  function color(r, g, b) {
    r = r * brightness / 255;
    g = g * brightness / 255;
    b = b * brightness / 255;
    return ((r & 0xff) << 16) + ((g & 0xff) << 8) + (b & 0xff);
  }
}
Ejemplo n.º 3
0
// Variable setup
// Setting up which led numbers on the strip correspond with which words.
// Each word has a 'begin' and an 'end' led number
// The leds numbers start from 1 and go to 110, in order from left -> right & top -> bottom
var itIsLeds = [[1,2],  [4,5]]
var descLeds = [[43,44], [45,48], [105,110]] // to, past, o'clock
// Minutes in time order (five, ten, quarter, twenty, half). Twenty five can just be amalgamated from twenty and five.
var minutesLeds = [[29,32], [39,41], [14,20], [23,28], [34,37]]
// Hours in sequential time order.
var hoursLeds = [[56,58], [75,77], [62,66], [67,70], [71,74], [59,61], [89,93], [78,82], [52,55], [100,102], [83,88], [94,99]]

var NUM_LEDS = 110
var pixelData = new Uint32Array(110)

neopixels.init(NUM_LEDS)

loop() // Start loop

// Main loop function
function loop() {
  parseTime(getTime())
  sleep.sleep(10)
  loop() // Call ourself so we're looped
}

function getTime() {
  // Get the current time.
  var currentTime = new Date()
  console.log(currentTime)
  var hour = currentTime.getHours()
Ejemplo n.º 4
0
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
 */

var ws281x = require('rpi-ws281x-native');

var NUM_LEDS = parseInt(process.argv[2], 10) || 8;
var PixelData = new Uint32Array(NUM_LEDS);

var MIDI_DEBUG = false;
var GAMMA_CORRECT = false;

ws281x.init(NUM_LEDS);

process.on('SIGINT', function () {
  ws281x.reset();
  midi_input.closePort();
  process.nextTick(function () { process.exit(0); });
});

console.log('Press <ctrl>+C to exit.');

// gamma = 2.2
var Gamma22=[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,8,8,8,9,9,9,10,10,10,11,11,11,12,12,13,13,14,14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,22,22,23,23,24,24,25,26,26,27,28,28,29,30,30,31,32,32,33,34,34,35,36,37,37,38,39,40,41,41,42,43,44,45,46,46,47,48,49,50,51,52,53,54,55,56,56,57,58,59,60,61,62,63,64,66,67,68,69,70,71,72,73,74,75,76,78,79,80,81,82,83,85,86,87,88,89,91,92,93,94,96,97,98,100,101,102,104,105,106,108,109,110,112,113,115,116,118,119,120,122,123,125,126,128,129,131,132,134,136,137,139,140,142,143,145,147,148,150,152,153,155,157,158,160,162,163,165,167,169,170,172,174,176,177,179,181,183,185,187,188,190,192,194,196,198,200,202,204,206,208,210,212,214,216,218,220,222,224,226,228,230,232,234,236,238,240,242,245,247,249,251,253,256];

// Fill all dots with the rgb_color
function colorFill(rgb_color) {
  var i;
Ejemplo n.º 5
0
	processData( function(err,data){
		console.log('doing processData');
		

		if (err){
				console.log(err);
			}
		else {

			//console.log(Object.keys(data).length);
			//console.log(data);
			ws2812x.init(NUM_LEDS);
			//pixelData[pixel] = rgb2Int(0,0,255);
			
            //ws2812x.render(pixelData);
            
            
         for (var l in data){
				console.log(l, data[l].distance);
				
				
				for (var i = 0; i <= NUM_LEDS ; i++){
					
				    var pixel = (data[l].distance);
				    pixel = Math.floor(pixel.map(0,125.86,0,63));
				    console.log('pixel = ' + pixel);
				    
					
					if (i === pixel ){
						

				        
				        pixelData[i] = rgb2Int(0,0,255);
				        
				        
						
						
					}
					
					else {
						
						pixelData[i] = rgb2Int(0,0,0);
						
						
						
					}
					
					
					
					
				}
				

				//var pixel = (data[l].LED_strip * 64) + distance;
				
				
				
				ws2812x.render(pixelData);
				




			}


			

		}


	});
Ejemplo n.º 6
0
exports.initLEDs = function(NUM_LEDs){

	ws2812x.init(NUM_LEDs);
	pixelData = new Uint32Array(NUM_LEDS);

}
Ejemplo n.º 7
0
var fs = require('fs');


var NUM_LEDS = 64;


var pixelData = new Uint32Array(NUM_LEDS);

var brightness = 128;


var LED_strip;

var LED_data = {};

ws2812x.init(NUM_LEDS);
ws2812x.reset();


// ---- trap the SIGINT and reset before exit
process.on('SIGINT', function () {
  ws2812x.reset();
  process.nextTick(function () { process.exit(0); });
});


function processData(callback){
	console.log('Process Data');

	fs.readFile('data/current.json',  function(err, myJson) {
Ejemplo n.º 8
0
exports.init = function(n) {
    ws281x.init(n); // 100 leds
}