gpio ruby gem allows for ruby code running on devices such as raspberry pi or systems with 1wire usb adapters to speak to the system's input/output pins. the end goal is for people to contribute code for specific devices, sensors and outputs.
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
benchmarks
examples
lib
.gitignore ignore .DS_Store Jun 9, 2012
README.md
changelog adding gpio mapping for revision 2 raspberry pi - fixes issue #1. Sep 29, 2012
gpio.gemspec

README.md

description

a ruby gem and repository to contribute gpio code for devices such as Raspberry Pi to read sensors and control outputs.

gpio allows for devices such as raspberry pi or systems with 1wire usb adapters to speak to the system's input/output pins.

installation

bundler

using bundler, add this to your Gemfile in the root of your app

gem 'gpio'

install bundler and then run bundle install

gem install bundler
bundle install

gem install

from command line

gem install gpio

require in your ruby file

require 'gpio'

example

let's setup a motion sensor on GPIO pin 17 on a RaspberryPi (default).

motion = GPIO::MotionDetector.new(pin: 17)

do we detect and motion yet?

motion.detect

let's print a message corresponding to the motion.detect?

puts motion.detect ? "Motion detected!" : "No motion detected."

was the value any different than the last time it detected?

motion.changed?
puts "last: #{motion.last_reading}, current: #{motion.reading}"

wait until the value changes before we move on.

until motion.changed? do
    motion.detect
    sleep 0.5
end
puts "Something changed!"
puts "last: #{motion.last_reading}, current: #{motion.reading}"