====
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.
====
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
from command line
gem install gpio
require in your ruby file
require 'gpio'
====
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}"