Sha256: 4f2c74daa6540c62930ca8dadb3f83e86057c7563089bc95e84518e0b61bfa55

Contents?: true

Size: 649 Bytes

Versions: 1

Compression:

Stored size: 649 Bytes

Contents

require_relative '../lib/frankenpins'

# Set up a rotary encoder that is connected to
# Wiring Pi pins #4 and #5 using a :pull => :up
# internal resistor by default. If you'd like to
# use external resistors on both pins, pass the
# option :pull => :none
encoder = Frankenpins::RotaryEncoder.new(:pin_a => 4, :pin_b => 5)

encoder.when :changed do |pos, direction|
  puts "position: #{pos}, direction: #{direction}"
end

# Use the Button class to watch the switch part of the
# encoder, push down to activate
button = Frankenpins::Button.new(:pin => 1)
button.when :pressed do
  puts "Button pressed"
end

puts "Rotate or push...."
Frankenpins.wait

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
frankenpins-0.3.0 examples/rotary_encoder.rb