Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var motorPin = 14;
var buttonPin = 4
var ledPin = 17
var blynkToken = 'blynk_token_here';
// *** Start code *** //
var locked = true
//Setup servo
var Gpio = require('pigpio').Gpio,
motor = new Gpio(motorPin, {mode: Gpio.OUTPUT}),
button = new Gpio(buttonPin, {
mode: Gpio.INPUT,
pullUpDown: Gpio.PUD_DOWN,
edge: Gpio.FALLING_EDGE
}),
led = new Gpio(ledPin, {mode: Gpio.OUTPUT});
//Setup blynk
var Blynk = require('blynk-library');
var blynk = new Blynk.Blynk(blynkToken);
var v0 = new blynk.VirtualPin(0);
console.log("locking door")
lockDoor()
button.on('interrupt', function (level) {
console.log("level: " + level + " locked: " + locked)
if (level == 0) {
RangeFinder.prototype.pingRead = function (callback) {
this._callback = callback;
this._startTick = undefined;
this._ignoreAlerts = false;
if (this._singlePin) {
this._triggerGpio.mode(Gpio.OUTPUT);
}
this._triggerGpio.trigger(10, 1);
if (this._singlePin) {
this._triggerGpio.mode(Gpio.INPUT);
}
this._timeout = setTimeout(function() {
if (this._singlePin) {
// Some hc-sr04 sensors appear to hang and don't timeout after 200000
// microseconds. Setting the pin-mode to output appears to force the
// timeout to occur.
this._triggerGpio.mode(Gpio.OUTPUT);
setTimeout(function () {
this._callback(0);
}.bind(this), 100);
} else {
this._callback(0);
}
}.bind(this), 250);
echoGpioNo = triggerGpioNo;
} else {
this._singlePin = false;
}
this._triggerGpio = new Gpio(triggerGpioNo, {
mode: Gpio.OUTPUT,
pullUpDown: Gpio.PUD_OFF,
alert: this._singlePin
});
if (this._singlePin) {
this._echoGpio = this._triggerGpio;
} else {
this._echoGpio = new Gpio(echoGpioNo, {
mode: Gpio.INPUT,
pullUpDown: Gpio.PUD_OFF,
alert: true
});
}
this._callback = undefined;
this._startTick = undefined;
this._ignoreAlerts = false;
this._timeout = undefined;
this._triggerGpio.digitalWrite(0);
// If a single pin is used for both trigger and echo there will be alert
// events for trigger pulses and echo pulses. Trigger pulses are ignored.
this._echoGpio.on('alert', function (level, tick) {
let endTick;
constructor(config: number | string | IConfig) {
const parsedConfig = parseConfig(config);
super(parsedConfig.pin);
this.pullResistor = parsedConfig.pullResistor;
this._input = new Gpio(getPin(parsedConfig.pin, this.pins[0]), {
mode: Gpio.INPUT,
pullUpDown: parsedConfig.pullResistor
});
this._input.enableInterrupt(Gpio.EITHER_EDGE);
this._input.on('interrupt', (level: number) => setTimeout(() => {
this._currentValue = level;
this.emit('change', this.value);
}));
this._currentValue = this._input.digitalRead();
}