-
Notifications
You must be signed in to change notification settings - Fork 120
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
Always returning 1 as new value during toggling #35
Comments
Is it because |
No it's just a typo in the question. Fixed. PS. I'm using Raspbian on a Raspberry Pi B. |
I would expect This line of code creates a new Gpio object called
This line of code reads the value of
This line of code therefore sets
What makes you think PS. Please don't modify previous posts as it makes it difficult/impossible to understand the topic later. |
So how can i read the value of led without setting it to 0? Doesn't exist a way to read the pin state? And for example how would you implement a toggling function without reading |
There appears to be a misunderstanding here. Reading the value of a Gpio object for a LED will _NOT_ set it's value to 0. What will set it's value to 0 is creating a new Gpio object for the LED. If the program is continuously creating Gpio objects for the LED, then the value will continuously be set to 0. This should be avoided. Please try the following program and let us know if it functions correctly. It toggles the state of a LED on GPIO 17 every 200ms, 25 times: var Gpio = require('onoff').Gpio,
led = new Gpio(17, 'out');
(function blink(count) {
if (count <= 0) {
return led.unexport();
}
led.read(function (err, value) {
led.write(value ^ 1, function (err) {
});
});
setTimeout(function () {
blink(count - 1);
}, 200);
}(25)); |
As you suggested, every new Gpio object sets the value to 0. Thanks, now all works fine ;) |
That's good news :) |
Someone can explain why it returns always 'off' in stato? It can't toogle.
For example, when i turn on the pin with a write method, everything seems to work fine, but when i try to read the pin status, the pin turn OFF and the value printed on the console is 0/off.
The weird thing is that it happens even with the rpi-gpio.js library: JamesBarwell/rpi-gpio.js#24
The text was updated successfully, but these errors were encountered: