-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwater_sensor.py
69 lines (59 loc) · 2.64 KB
/
water_sensor.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import RPi.GPIO as GPIO
import time
from display import LcdDisplay
from display import TextJustification
from air_temperature_and_humidity import AirTemperatureAndHumidity
from water_temperature import WaterTemperature
from ph_sensor import PhSensor
from ec_sensor import EcSensor
from menu_buttons import MenuButtons
from calibrate_ph_menu import CalibratePhMenu
class WaterSensor:
def __init__(self):
self.display = LcdDisplay()
self.air_temperature = AirTemperatureAndHumidity(22, 17)
self.water_temperature = WaterTemperature()
self.ph_sensor = PhSensor()
self.ec_sensor = EcSensor()
self.menu_buttons = MenuButtons()
def start(self):
while True:
if(self.menu_buttons.is_next_pressed()):
ph_menu = CalibratePhMenu(self.ph_sensor)
ph_menu.start()
self.__get_water_temperature()
self.__get_air_temperature_and_humidity()
self.__get_ph()
self.__get_ec()
self.__update_display()
time.sleep(3)
def __get_air_temperature_and_humidity(self):
self.humidity, self.air_temp = self.air_temperature.read()
self.humidity = round(self.humidity, 2)
self.air_temp = round(self.air_temp, 2)
def __get_water_temperature(self):
self.water_temp = self.water_temperature.read()
def __get_ph(self):
self.__ph = self.ph_sensor.read()
def __get_ec(self):
self.__ec = self.ec_sensor.read()
def __update_display(self):
self.display.write_line(self.display.LINE_1,
"Air {:05.2f} Wtr {:05.2f}".format(self.air_temp, self.water_temp))
self.display.write_line(self.display.LINE_2,
"Humidity {}%".format(self.humidity))
self.display.write_line(self.display.LINE_3,
"pH {:05.2f} Raw {}"
.format(self.__ph.get_value(),
self.__ph.get_raw_value()))
self.display.write_line(self.display.LINE_4,
"EC {:05.2f} Raw {}".format(self.__ec.get_value(),
self.__ec.get_raw_value()))
def __print_debug(self):
print("Air {:05.2f} Wtr {:05.2f}".format(self.air_temp, self.water_temp))
print("Humidity {}%".format(self.humidity))
print("pH {:05.2f} Raw {}".format(self.__ph.get_value(),
self.__ph.get_raw_value()))
print("EC {:05.2f} Raw {}".format(self.ec, self.ec_raw))
def __del__(self):
GPIO.cleanup()