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
Latest commit 75f4dcb Jan 7, 2015 @klappy Merge pull request #6 from galp/beaglebone
Adding support for beaglebone black
Permalink
Failed to load latest commit information.
benchmarks benchmarks to support last commit of file vs io Jun 9, 2012
examples traffic_light.rb: new output of traffic light and an example to test it Jun 14, 2012
lib Adding support for beaglebone black Jan 7, 2015
.gitignore ignore .DS_Store Jun 9, 2012
README.md updated readme Jun 5, 2012
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}"