Closed MinasMazar closed 6 years ago
Value can accepts only 4 digits. Next improvement is to pass freq and duration parameters of Dino::tone both on auxMsg.
Don't know how I missed this. Good work! I notice you use the duration parameter of the native tone()
function. What happens if you try doing the timing in Ruby?
I think this can be easily done.. calling the tone() method (without duration parameter), start a timeout (sleep) and then send a noTone(). But is there a particular reason for adopting this implementation?
I haven't tested this, but using tone()
with the duration parameter seems to block execution for that duration (i.e. stops more commands from being processed by the board), while using it without the duration starts the tone and continues execution.
If, for example, you have Ruby code that blinks an LED with a specific timing on the same board, the timing can be thrown off by this. If a tone (with duration sent) is playing while a command to toggle the LED state comes in, that command has to wait until the tone finishes playing, instead of happening when it should.
If you move all the timing logic into the Ruby code, you free up the board to toggle the LED as soon as the command comes in. I'm using an LED as an example here, but it could be any other operation that needs to happen while the tone plays.
Just tested and I do not see the behaviour you describe... I execute that in the IRB:
2.0.0-p451 :042 > piezo.tone 222, 8000 => nil 2.0.0-p451 :043 > led.blink
and it blinks while piezo sounds.. however if you think move timing logic in Ruby is better, i'll do it ;)
ps. what about the Piezo#tone method called without duration parameter? Current implementation take a duration default parameter of 0.5 sec, but it can be implemented a register that remember last duration..
I ended up patching this in manually to 0.12 since your fork seems to be missing.
This respond to http://github.com/austinbv/dino/issues/70 This modify board.rb, Dino.h and Dino.cpp in order to respond tone/noTone Arduino commands and add a piezo.rb component.