class Frankenpins::Button
Public Class Methods
new(options)
click to toggle source
# File lib/frankenpins/button.rb, line 11 def initialize(options) options[:pull] = :up unless options.has_key?(:pull) @pin = Frankenpins::Pin.new(options) @pin.watch do |pin| if pin.value == 0 raise_event :pressed elsif pin.value == 1 raise_event :released end # Always fire a changed event raise_event :changed end end
Public Instance Methods
when(event_name, &block)
click to toggle source
# File lib/frankenpins/button.rb, line 27 def when(event_name, &block) send(event_name).register(&block) end