Skip to content

Commit

Permalink
Change AS312 class to GenericPIR and use it for HC-SR501 sensor too
Browse files Browse the repository at this point in the history
  • Loading branch information
vickash committed Oct 8, 2023
1 parent fbae4d3 commit 0380a63
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 24 deletions.
12 changes: 6 additions & 6 deletions HARDWARE.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,11 @@ Polling and reading follow a call and response pattern.
| TCS34725 | :heart: | I2C | `Sensor::TCS34725` | RGB
| APDS9960 | :heart: | I2C | `Sensor::APDS9960` | Proximity, RGB, Gesture

### PIR Sensors
| Name | Status | Interface | Component Class | Notes |
| :--------------- | :------: | :-------- | :--------------- |------ |
| HC-SR501 | :yellow_heart: | Digital In | `DigitalIO::Input` | PIR. Needs class: `Sensor::HC-SR501`
| AS312 | :green_heart: | Digital In | `Sensor::AS312` | PIR (based on `DigitalIO::Input`)
### PIR Motion Sensors
| Name | Status | Interface | Component Class | Notes |
| :--------------- | :------: | :-------- | :--------------- |------ |
| HC-SR501 | :green_heart: | Digital In | `Sensor::GenericPIR` |
| AS312 | :green_heart: | Digital In | `Sensor::GenericPIR` |

### Distance Sensors

Expand All @@ -219,7 +219,7 @@ Polling and reading follow a call and response pattern.
| VL53L0X | :heart: | I2C | `Sensor::VL53L0X` | Laser, 30 - 1000mm
| GP2Y0E03 | :heart: | I2C | `Sensor::GP2Y0E03` | Infrared, 40 - 500mm

### Motion Sensors
### Inertial Measurement Units

| Name | Status | Interface | Component Class | Notes |
| :--------------- | :------: | :-------- | :--------------- |------ |
Expand Down
16 changes: 0 additions & 16 deletions examples/sensor/as312.rb

This file was deleted.

25 changes: 25 additions & 0 deletions examples/sensor/generic_pir.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
# Example using a PIR motion sensor. Tested with AS312 and HC-SR501 sensors.
#
# General notes:
# - Both sensors have a few seconds "dead time" after "motion stop" (logical 0), where further
# motion will not trigger "motion start" (logical 1).
#
# HC-SR501 notes:
# - Needs some time to warm up and start working properly.
# - Set the time potentiometer to its lowest value.
# - Make sure retriggering is enabled. It might be default, but there's a jumper to solder too.
#
require 'bundler/setup'
require 'denko'

board = Denko::Board.new(Denko::Connection::Serial.new)
sensor = Denko::Sensor::GenericPIR.new(board: board, pin: 8)

sensor.on_motion_start { print "Motion detected! \r" }
sensor.on_motion_stop { print "No motion detected...\r" }

# Read initial state.
sensor.read

sleep
2 changes: 1 addition & 1 deletion lib/denko/sensor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ module Sensor
autoload :SHT3X, "#{__dir__}/sensor/sht3x"
autoload :QMP6988, "#{__dir__}/sensor/qmp6988"
autoload :RCWL9620, "#{__dir__}/sensor/rcwl9620"
autoload :AS312, "#{__dir__}/sensor/as312"
autoload :GenericPIR, "#{__dir__}/sensor/generic_pir"
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Denko
module Sensor
class AS312 < DigitalIO::Input
class GenericPIR < DigitalIO::Input
alias :on_motion_stop :on_low
alias :on_motion_start :on_high
end
Expand Down

0 comments on commit 0380a63

Please sign in to comment.