-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
board.reportDigitalPin(digitalPinNumber, 0) has no effect #185
Comments
Are you trying to read the value of a pin infrequently using analogRead or digitalRead, and do not want the callbacks there after? I was trying to do that and made my code look as follows function readPin(pinId) {
board.pinMode( pinId, board.MODES.INPUT );
board.digitalRead(pinId, function(value) {
console.log("The value of digital pin changed to: " + value);
board.reportDigitalPin(pinId, 0);
});
} With this change, I got warning of maxEventListeners after calling the function readPin 10 times. I think there is a need of analogReadOnce and digitalReadOnce type of functions. The code there can simply call "this.once" instead of "this.addListener" so that the above code would work and user would not need to tamper with the listeners directly. Board.prototype.analogReadOnce = function(pin, callback) {
this.reportAnalogPin(pin, 1);
this.once("analog-read-" + pin, callback);
}; |
When you observe this, do you mean that it logs once, or continuously? I can reproduce the behavior in which a single report still occurs, but not continuous reports. |
@rwaldron Thanks. The commits that you made also help solve the problem. The only change I made to my code is moved the reportDigitalPin(pinId, 0) as the first thing to do in the callback. function readPin(pinId) {
board.pinMode( pinId, board.MODES.INPUT );
board.digitalRead(pinId, function(value) {
board.reportDigitalPin(pinId, 0);
console.log("The value of digital pin changed to: " + value);
});
} |
From the Documentation:
Reproduce the Error:
The log message is still written to the console, when Pin 2 is toggled.
Hack:
Now, no message is written.
The text was updated successfully, but these errors were encountered: