Monitoring GPIO pins with the Pi Piper gem

Installation

gem install pi_piper

Example

require 'pi_piper'
include PiPiper

watch :pin => 7 do
  puts "Pin changed from #{last_value} to #{value}"
end
PiPiper.wait

The foll owing output was generated from a PIR sensor connected on pin 7:

Pin changed from 0 to 1
Pin changed from 1 to 0
Pin changed from 0 to 1
Pin changed from 1 to 0
Pin changed from 0 to 1
Pin changed from 1 to 0
Pin changed from 0 to 1
Pin changed from 1 to 0
Pin changed from 0 to 1
Pin changed from 1 to 0

updated

I found the following code more appropriate for the PIR sensor:

after pin: 7, goes: :high do
  puts Time.now.to_s 
end
PiPiper.wait

Resources

Tags:
Source:
1853hrs.txt
Published:
06-04-2013 18:53