I
I
Iren_Zigrin2016-01-07 23:52:08
Node.js
Iren_Zigrin, 2016-01-07 23:52:08

Raspberry Pi node.js I run the code, writes GPIO port (pin) is not defined?

Please help, I have a raspberry Pi with node.js installed and everything else that is needed and not so much. As well as an LED connected to the GPIO ports (GPIO4 (P1-07) and Ground (P2-06)). I run a code that should, in theory, make it blink the LED (+ allow them to still manage over the Internet from the specified site):

var socket = require('socket.io-client')('http://bk-it.ru:3141');
var gpio = require('rpi-gpio');
var fs = require('fs');

// hack due to error
fs.exists = require('path').exists;
var async = require('async');

// pin GPIO4
var pin = 7;

// current fps
var piFps = 2;
var currentValue = false;
var timemanager;


var set0 = function(err, results) {
    if (err)
        console.log(err);
    console.log('Pin ' + pin + ' closed');
    directWrite(pin, false, function() {
        clearTimeout(timemanager);
    });
};

var stopblink = true;

var blinkexec = function() {
    delayedWrite(7, true, function() {
        delayedWrite(7, false, blinkexec)
    });
};

var blink = function(err, results) {
    if (err)
        console.log(err);
    console.log('Pin ' + pin + ' blinking');
    blinkexec();
};


function directWrite(pin, value, callback) {
    return gpio.write(pin, value, callback);

}
function delayedWrite(pin, value, callback) {
    var delay = Math.round(1000 / piFps / 2);
    
    clearTimeout(timemanager);
    timemanager = setTimeout(function() {
        directWrite(pin, value, callback);
    }, delay);
}


var release = function() {
    console.log('Writes complete, pause then unexport pins');
    setTimeout(function() {
        gpio.destroy(function() {
            console.log('Closed pins, now exit');
            return process.exit(0);
        });
    }, 500);
};

In general, this is what it gives out: caa90f8ace2a4f6f90ea8b6bf71053fb.png
PS I understand that the translation of the error "port is not defined." I'm a teapot :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pomeo, 2016-01-08
@pomeo

I understand that the translation of the error "port is not defined"

The error is not about the port, but about the variable called "pin".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question