Example #1
0
lightSensor.get = (cb) => {
    gpio.read(sensorPin, (err, value) => {
        if (err) throw err;
        console.log('The value is ' + value);
        if(cb)cb(value);
    });
}
Example #2
0
	function readInput(){
    gpio.read(10, function(err, value){
    	var date = new Date().getTime();
      socket.emit('gas', value, date);

			//Variable para el update en la Base de Datos
			casaGas = value;
		});
  }
Example #3
0
gpio.setup(BTN, gpio.DIR_IN, function() {
    gpio.read(BTN, function(err, value) {
	if (err) {
	    console.log(err);
	} else {
	    console.log('Button state: ' + value);
	}
    });
});
Example #4
0
var readInterval = function() {
  gpio.read(pir.pin, function(error, value) {
    // we only want to move on if something changed
    if (value === pir.tripped) return

    pir.tripped = value
    if (pir.tripped) takePicture()
    else console.log('waiting...')
  })
}
Example #5
0
	basic.apply(req, res, function(username) {
		gpio.read(7,function(err,result){
        	if(result){
				res.writeHead(200, {'Content-Type': 'text/plain'});
				  res.end('true');
			}else{
				res.writeHead(200, {'Content-Type': 'text/plain'});
				  res.end('false');
			}		
			});
		
		});
Example #6
0
  setInterval(function () {
    gpio.read(_this.pin, function (err, val) {
      _this.emit('data', val);

      if (err) _this.emit('error', err);

      if (changed(previous, val, changeTime, _this.delay)) {
        changeTime = Date.now();
        _this.emit('change', val);
      }

      previous = val;
    });
  }, this.interval);
Example #7
0
function checkInput(){
	gpio.read(7, function(err, value)
	{
		if(inputStatus != value)
		{
			socket.emit('statusMessage', {
			        power: value,
			        ID: 2
			});

		}
        	inputStatus = value;
        });
}
Example #8
0
		this.setup(function(){
			console.log("Pin " + this.initData.gpioPort + " opened");
			if(this.inout == gpio.DIR_IN){
				
				var out = this.initData.out;
				
				for(var i in out){
					if(out[i].onChange){
						var executed = false;
						gpio.on('change', function(channel, value) {
							if(!executed){
								executed = true;
								console.log('Channel ' + channel + ' value is now ' + value);
								if(channel == this.initData.gpioPort){
									this.myEmitter.once('unexported' + this.initData.gpioPort, function() {
										this.next(out[i].target);
									}.bind(this));
									
									this.unexport();
								}
							}
						}.bind(this));
					} else {
						gpio.read(this.initData.gpioPort, function(err, value) {
							if (err) throw err;
							
							if(this.initData.input && this.initData.input.time){
								console.log(this.initData.input.time);
								var max_sec = new Date().getTime();
								while (new Date() < max_sec + this.initData.input.time) {}
							}
							
							this.next(out[i].target);
					    }.bind(this));
					}
				}
			} else {
				gpio.write(this.initData.gpioPort, this.initData.value, function(err) {
			        if (err) throw err;
			        
			        this.handleTimeout();
			        
			        this.myEmitter.once('unexported' + this.initData.gpioPort, function() {
			        	this.handleOutputs();
					}.bind(this));
			        
			        this.unexport();
			    }.bind(this));
			}
		}.bind(this));
Example #9
0
function readInput() {
    gpio.read(in_pin, function(err, value) {
        if (err) {
           throw err;
        }

        btnprev = btncurr;
        btncurr = value;

        if (btnprev !== btncurr) {
            emitter.emit(btncurr ? BTNUP : BTNDOWN);
        }
        readInput();
    });
}
Example #10
0
monitorButton = function () {
  //Iniate a read of the button
  gpio.read(button.pin, function (err, value) {
    //Emit an error if one is detected
    if (err) {
      button.emit('error', err);
    } else {
      //If the button state differs from the current state process the events
      if (button.state !== value) {
        button.emit('stateChange', button.state, value);
        button.state = value;

        if (value) { button.emit('pressed'); }
        if (!value) { button.emit('released'); }
      }
    }
  });
};
Example #11
0
function readInput() {
    gpio.read(led, function(err, value) 
    {
    	console.log('The value is ' + value);
	if(value)
	{
		socket.emit('statusMessage', {
			power: 1,
			ID: 2 //send to human :D
		});
	}
	else
	{
		socket.emit('statusMessage', {
			power: 0,
			ID: 2 //send to human :D
		});
	}
    });
}
// Check motion sensor
function checkSensor() {
  gpio.read(motionSensorPin, function(err, value) {

      // If motion is detected
      if (value == true && motionSensorState == false) {

        // Send event
        alertIFTTT(eventOnName);

      }

      // No motion anymore
      if (value == false && motionSensorState == true) {

        // Send event
        alertIFTTT(eventOffName);

      }

      // Set status
      motionSensorState = value;
  });
}
Example #13
0
 function readInput(){
   gpio.read(8, function(err, value){
     var date = new Date().getTime();
     socket.emit('gas', value, date);
   });
 }
Example #14
0
function readInput() {
    gpio.read(4, function(err, value) {
        console.log('The value is ' + value);
    });
}
Example #15
0
var listener = setInterval(function(){gpio.read(8, function(err, value) {console.log('The value is ' + value);});	},3000);
Example #16
0
 function(next) {
     gpio.read(readPin, function(err, value) {
         readValue = value;
         next();
     });
 }