Project

rpi_pinin

0.0
No commit activity in last 3 years
No release in over 3 years
Represents a Raspberry Pi GPIO pin in e.g. to read a button press.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

Detecting a button press using the rpi_pinin gem

require 'rpi_pinin'

pin = RPiPinIn.new(17, pull: :up)
pin.watch do |v|

  puts Time.now.to_s + ': ' + v.inspect

end

In the above example the rpi_pinin gem is used to detect a button press from a momentary push button switch connected between GPIO 17 and ground.

Output:

2016-10-17 11:02:26 +0000: 1
2016-10-17 11:02:27 +0000: 0
2016-10-17 11:02:33 +0000: 1
2016-10-17 11:02:34 +0000: 0

Notes:

  • The internal pullup resistor was used
  • If you don't have a momentary push button switch you can simulate a button press using 2 jumpers (1 to GPIO 17 and the other to ground) which then touch each other momentarily.

Resources

see also

rpi_pinin button rpi raspberrypi