Skip to content

Button Example Wrong Number of Arguments #17

Closed
DaveCollinsJr opened this Issue Dec 5, 2012 · 9 comments

4 participants

@DaveCollinsJr

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

@austinbv
Owner
austinbv commented Dec 7, 2012

I will look into it tomorrow. Sorry about that.

@DaveCollinsJr

No problem. Let me know how I can help! Thanks

@melissavoegeli

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.

@austinbv
Owner
austinbv commented Dec 8, 2012

Ah did I forget to push the new gem

@DaveCollinsJr
@DaveCollinsJr

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.

@DaveCollinsJr

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!!

@austinbv
Owner

@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.

@melissavoegeli

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.

@vickash vickash closed this May 24, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.