25 lines
710 B
Python
25 lines
710 B
Python
# Moisture Sensor Class
|
|
from machine import ADC, Pin
|
|
|
|
|
|
class MoistureSensor:
|
|
moisture_sensor_pin_int = -1
|
|
|
|
moisture_sensor = None
|
|
|
|
most_recent_value = []
|
|
|
|
def __init__(self, moisture_sensor_data):
|
|
self.moisture_sensor_pin_int = moisture_sensor_data['pin_int']
|
|
print("Hello from moisture sensor. Sensor pin is: " + str(self.moisture_sensor_pin_int))
|
|
self.moisture_sensor = ADC(Pin(self.moisture_sensor_pin_int))
|
|
|
|
def read(self):
|
|
self.most_recent_value = [
|
|
{
|
|
'type': 'moisture',
|
|
'value': self.moisture_sensor.read_u16(),
|
|
'unit': 'unknown'
|
|
},
|
|
]
|