theoctal / octalbonescript

A more stable, continuously tested and better node.js library for scripting your BeagleBone
MIT License
57 stars 9 forks source link

double calling pinmode on PWM disables output #32

Closed TechplexEngineer closed 9 years ago

TechplexEngineer commented 9 years ago

In the following test code calling the pinmode each time causes the output to be terminated.

Consider the following example:

var b = require('octalbonescript'); //load the library

var pin = 'P9_14'; //the pin to operate on
var duty = .05;
var freq = 50;

function test(cb) {
    b.pinMode(pin, b.OUTPUT, function (err) {
        if (err)
            console.log (err);
        else {
            b.analogWrite (pin, duty, freq, function(x) {
                console.log(x);
                if (cb)
                    cb(null);
            });
        }
    });
}
test(function(){
    test();
});

However this works:

var b = require('octalbonescript'); //load the library

var pin = 'P9_14'; //the pin to operate on
var duty = .05;
var freq = 50;

function test(cb) {
    b.analogWrite (pin, duty, freq, function(x) {
        console.log(x);
        if (cb)
            cb(null);
    });
}

b.pinMode(pin, b.OUTPUT, function (err) {
    if (err)
        console.log (err);
    else {
        test(function(){
            test();
        })
    }
});
TechplexEngineer commented 9 years ago

However setting the pinMode to ANALOG_OUTPUT the code works as expected.

var b = require('octalbonescript'); //load the library

var pin = 'P9_14'; //the pin to operate on
var duty = .05;
var freq = 50;

function test(cb) {
    b.pinMode(pin, b.ANALOG_OUTPUT, function (err) {
        if (err)
            console.log (err);
        else {
            b.analogWrite (pin, duty, freq, function(x) {
                console.log(x);
                if (cb)
                    cb(null);
            });
        }
    });
}
test(function(){
    test();
});
adityapatadia commented 9 years ago

Yes, because b.OUTPUT means digital output and b.ANALOG_OUTPUT means PWM.