16 lines
346 B
Python
16 lines
346 B
Python
import machine
|
|
|
|
|
|
class WaterSensor:
|
|
|
|
def __init__(self, pin):
|
|
self.waterSensor = machine.ADC(pin)
|
|
self.reading = self.waterSensor.read_u16()
|
|
self.threshold = 2000
|
|
|
|
def takeReading(self):
|
|
self.reading = self.waterSensor.read_u16()
|
|
|
|
def isWaterPresent(self):
|
|
return self.reading > self.threshold
|