Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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) {
if (locked) {
unlockDoor()
} else {
lockDoor()
var unlockedState = 1000;
var lockedState = 2200;
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) {
prevmax = max ; max = 0 ; index += step ;
}, interval,pcmdata);
}
/*********************************************************************
* Step #: Wave Arm
*********************************************************************
*/
var mincycle = 500; var maxcycle = 2300 ;
var dutycycle = mincycle;
// Setup software PWM on pin 26, GPIO7.
var Gpio = require('pigpio').Gpio;
var motor = new Gpio(7, {mode: Gpio.OUTPUT});
function waveArm() {
motor.servoWrite(maxcycle);
setTimeout(function(){
motor.servoWrite(mincycle);
}, 400);
}
// Hardware PWM used for LED "sometimes" conflicts with audio, you can uncomment and try it.
// var ws281x = require('rpi-ws281x-native');
// var NUM_LEDS = 1; // Number of LEDs
// var colorPalette = {
// "red": 0x00ff00,
// "read": 0x00ff00, // sometimes, STT hears "read" instead of "red"
// "green": 0xff0000,
// "blue": 0x0000ff,
// Modules
var Gpio = require('pigpio').Gpio;
var express = require('express');
// Express app
var app = express();
// Use public directory
app.use(express.static('public'));
// Create led instance
var motorSpeed = new Gpio(18, {mode: Gpio.OUTPUT});
var motorDirectionOne = new Gpio(14, {mode: Gpio.OUTPUT});
var motorDirectionTwo = new Gpio(15, {mode: Gpio.OUTPUT});
// Routes
app.get('/', function (req, res) {
res.sendfile(__dirname + '/public/interface.html');
});
app.get('/set', function (req, res) {
// Set motor speed
speed = req.query.speed;
motorSpeed.pwmWrite(speed);
// Modules
var Gpio = require('pigpio').Gpio;
var express = require('express');
// Express app
var app = express();
// Use public directory
app.use(express.static('public'));
// Create led instance
var led = new Gpio(18, {mode: Gpio.OUTPUT});
// Routes
app.get('/', function (req, res) {
res.sendfile(__dirname + '/public/interface.html');
});
app.get('/set', function (req, res) {
// Set LED
dutyCycle = req.query.dutyCycle;
led.pwmWrite(dutyCycle);
// Answer
answer = {
/////////////////////////////////
// MAIN SETUP VARIABLES
bc._BOT_ID = config.botID // || 'drawbot'
bc._DIRSWAP = config.swapDirections // || [true, true]
bc.baseDelay = config.baseDelay // || 2
bc._D = config.d // || 1000// default distance between string starts
bc.startPos = config.startPos // || { x: 100, y: 100 }
bc.stepsPerMM = config.stepsPerMM // || [5000/500, 5000/500] // steps / mm
bc.penPause = config.penPauseDelay // || 200 // pause for pen up/down movement (in ms)
/////////////////////////////////
// GPIO SETUP
var gmOut = {mode: Gpio.OUTPUT}
var dirPins = [
new Gpio(config.pins.leftDir, gmOut),
new Gpio(config.pins.rightDir, gmOut)
]
var stepPins = [
new Gpio(config.pins.leftStep, gmOut),
new Gpio(config.pins.rightStep, gmOut)
]
// set up servo GPIO pin
var servo = new Gpio(config.pins.penServo, gmOut)
// ^ Step resolution Pins
const leftMotorMs1= new Gpio(config.stepResolutionPins.leftMotor.ms1, gmOut)
const leftMotorMs2= new Gpio(config.stepResolutionPins.leftMotor.ms2, gmOut)
const leftMotorMs3= new Gpio(config.stepResolutionPins.leftMotor.ms3, gmOut)
const rightMotorMs1= new Gpio(config.stepResolutionPins.rightMotor.ms1, gmOut)
// Modules
var Gpio = require('pigpio').Gpio;
var express = require('express');
// Express app
var app = express();
// Use public directory
app.use(express.static('public'));
// Create led instance
var motorSpeed = new Gpio(18, {mode: Gpio.OUTPUT});
var motorDirectionOne = new Gpio(14, {mode: Gpio.OUTPUT});
var motorDirectionTwo = new Gpio(15, {mode: Gpio.OUTPUT});
// Routes
app.get('/', function (req, res) {
res.sendfile(__dirname + '/public/interface.html');
});
app.get('/set', function (req, res) {
// Set motor speed
speed = req.query.speed;
motorSpeed.pwmWrite(speed);
// Set motor direction
motorDirectionOne.digitalWrite(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 () {
constructor(config: number | string | IConfig) {
const parsedConfig = parseConfig(config);
super(parsedConfig.pin);
this._output = new Gpio(getPin(parsedConfig.pin, this.pins[0]), {
mode: Gpio.OUTPUT,
pullUpDown: parsedConfig.pullResistor
});
this._currentValue = this._output.digitalRead();
}
function RangeFinder(triggerGpioNo, echoGpioNo) {
if (!(this instanceof RangeFinder)) {
return new RangeFinder(triggerGpioNo, echoGpioNo);
}
if (triggerGpioNo === echoGpioNo || typeof(echoGpioNo) !== 'number') {
this._singlePin = true;
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;