-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsensor_gas.py
More file actions
executable file
·33 lines (24 loc) · 862 Bytes
/
sensor_gas.py
File metadata and controls
executable file
·33 lines (24 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import logging
from sensor import Sensor
try:
import RPi.GPIO as GPIO
except ImportError:
from fake_rpi.RPi import GPIO
class SensorGas(Sensor):
def __init__(self):
super().__init__()
self.name = 'gas'
self.setup_gas_sensor()
def setup_gas_sensor(self):
gas_sensor_pin = 7
def gas_callback(_):
if GPIO.input(gas_sensor_pin) == 1:
logging.info('Gas event detected')
self.counter += 1
# Use physical pin numbering
GPIO.setmode(GPIO.BOARD)
# Set pin SensorPin to be an input pin and set initial value to be pulled low (off)
GPIO.setup(gas_sensor_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.add_event_detect(gas_sensor_pin, GPIO.RISING, callback=gas_callback)
def cleanup(self) -> None:
GPIO.cleanup()