The function digitalRead returns the value of the pin does it not?
This I do not know first hand as I have never used bonescript. What I can say is that typically, when calling an executable directly from Nodejs ( which is what bonescript uses - Nodejs ), you need to use a callback to capture the output of that executable if you wish to use that value from within the script.
What I do imagine, as far as how bonescript works. Is that it directly calls an executable of some sort ( custom, or Linux command ), which then returns a value depending on which mode the pin is set as. Jason Kridner should know for sure since he wrote the library, and I could be wrong. I never really examined his code all that well, before I decided it was not for me.
Basically what I ask is, if reading the return value of the digitalRead is enough, of should I capture the value of the pin via a callback function.
Ok, so if bonescript does in fact return a value, and if correct ( without a callback ), then there should be no problem. You could / should test the value to make sure it is correct though.
I am writing a small program where I interchange the mode of a pin as input and output. I am having difficulties doing that. I am a newbie in javascript, but I am wondering if that is possible at all.
Thanks in advance
I have read on these groups from various people that using a single pin ( GPIO - read / write ) is possible. However, I am left wondering in which case that would be useful. Whatever the case, digitalRead would only work when the pin is configured as GPIO → IN.
Two ways I think you may be able to do this is using . . .
https://github.com/cdsteinkuehler/beaglebone-universal-io - This would be slow-ish, but you could call config-pin directly from Nodejs.
or by using pin(s) the PRU’s can switch modes for fast. For something like say a buffer<->external memory. This way would also be far more complex, but should be vastly faster than using universal-io.