Introducing the HumbleRPi-plugin-knocksensor gem

Testing the plugin

require 'humble_rpi-plugin-knocksensor'


class Echo

  def notice(s)
    puts "%s: %s" % [Time.now, s]
  end
end

sensor = HumbleRPiPluginKnockSensor.new(settings: {pin: 0}, 
                                        variables: {notifier: Echo.new})
sensor.start

Output:

2016-03-06 22:53:02 +0000: pi/knock: detected
2016-03-06 22:53:02 +0000: pi/knock: detected
2016-03-06 22:53:03 +0000: pi/knock: detected
2016-03-06 22:53:03 +0000: pi/knock: detected
2016-03-06 22:53:04 +0000: pi/knock: detected
2016-03-06 22:53:05 +0000: pi/knock: detected
2016-03-06 22:53:06 +0000: pi/knock: detected
2016-03-06 22:53:06 +0000: pi/knock: detected
2016-03-06 22:53:07 +0000: pi/knock: detected
2016-03-06 22:53:07 +0000: pi/knock: detected
2016-03-06 22:53:08 +0000: pi/knock: detected
2016-03-06 22:53:09 +0000: pi/knock: detected
2016-03-06 22:53:09 +0000: pi/knock: detected

Note: The default threshold is set to 10, and the default analog pin is set to 0.

Using the plugin with the HumbleRPi gem

require 'humble_rpi'
require 'humble_rpi-plugin-knocksensor'

r = HumbleRPi.new device_name: 'ottavia', sps_address: '192.168.4.140',\
  plugins: {KnockSensor: {pin: 0} }
r.start

Resources

See also