Button Example Wrong Number of Arguments
Closed this issue · 9 comments
Hello,
Nice project! I have the LED example working fine on my Arduino.
The button example, when I run it, gives me this error:
/.rvm/gems/ruby-1.9.3-p194/gems/dino-0.9.1/lib/dino/components/button.rb:14:in 'down': wrong number of arguments (0 for 1) (ArgumentError) from dino/examples/button/button.rb:12:in `
Looking at the code, it seems that the .down and .up methods need a callback?
So I tried changing the code to this:
on_data = Proc.new do |data|
puts "On Data:#{data.to_i}"
end
button.down(on_data) do
puts "button down"
end
button.up(on_data) do
puts "button up"
end
and then that runs, but control never gets to the inside of the on_data proc (even though I can see on the serial monitor the pin going from 13::00 to 13:01)
Any ideas what I might be doing wrong?
Thanks!
Dave
I will look into it tomorrow. Sorry about that.
No problem. Let me know how I can help! Thanks
This might be related: it looks like the gem Dino 0.9.1 and the source on Github are slightly different
# Dino Gem 0.9.1
def down(callback)
@down_callbacks << callback
end
def up(callback)
@up_callbacks << callback
end
# Dino Gem Github
def down(&callback)
@down_callbacks << callback
end
def up(&callback)
@up_callbacks << callback
end
If you're calling button.up from the Gem:
p = Proc.new { puts 'button up' }
button.up(p)
If you're calling button.up from the Github source:
button.up { puts 'button up' }
If you're using the gem, then it would call on_data, but ignore button up/down.
Ah did I forget to push the new gem
I had installed if following the directions, which was to use a gem install dino.
Would it be recommended to blow that away and just clone the repository?
Thanks,
Dave
On Dec 8, 2012, at 3:18 PM, Austin wrote:
Ah did I forget to push the new gem
—
Reply to this email directly or view it on GitHub.
Hmmm. This is strange. I just did a git clone to a clean directory and I'm still seeing this in my \components\button:
def down(&callback)
@down_callbacks << callback
end
def up(&callback)
@up_callbacks << callback
end
(which I guess isn't that strange as that is what is on github right now) and the example still has the wrong number of arguments error.
Melissa your code was right on the money! Here is a working button.rb for me now:
#
# This is an example of how to use the button class
# You must register helpers and have the main thread
# sleep or in someway keep running or your program
# will exit before any callbacks can be called
#
require File.expand_path('../../../lib/dino', __FILE__)
board = Dino::Board.new(Dino::TxRx.new)
button = Dino::Components::Button.new(pin: 13, board: board)
up_proc = Proc.new do
puts 'button up'
end
down_proc = Proc.new do
puts 'button down'
end
button.down(down_proc)
button.up(up_proc)
sleep
Thanks!!
@RalfieRoo if you make a pull request I will accept it so you can have your name on the repo, otherwise I will do it tomorrow.
The repo is internally consistent. If you're running the example button script with Github's lib source, then everything will work as expected. If you're using the gem Dino v0.9.1, then you need to change the button example script to pass in a proc as an argument and not provide a block. The gem needs to be updated to reflect the Github repo's changes.