parent
a9068ab80f
commit
082094ccc5
1
main.py
1
main.py
|
@ -29,7 +29,6 @@ def error_print(message: str):
|
||||||
print('[ERROR]['+current_time+'] '+message)
|
print('[ERROR]['+current_time+'] '+message)
|
||||||
|
|
||||||
#relay
|
#relay
|
||||||
|
|
||||||
def relay_controller(pin: int, status: str):
|
def relay_controller(pin: int, status: str):
|
||||||
if status == "ON":
|
if status == "ON":
|
||||||
relay = gpiozero.OutputDevice(pin, active_high=False, initial_value=False)
|
relay = gpiozero.OutputDevice(pin, active_high=False, initial_value=False)
|
||||||
|
|
49
test.py
49
test.py
|
@ -1,13 +1,42 @@
|
||||||
import board
|
# import board
|
||||||
import busio
|
# import busio
|
||||||
import adafruit_bmp280
|
# import adafruit_bmp280
|
||||||
|
# import time
|
||||||
|
|
||||||
|
# def get_temperature():
|
||||||
|
# i2c = busio.I2C(board.SCL, board.SDA)
|
||||||
|
# bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c, address=0x76)
|
||||||
|
# return bmp280.temperature
|
||||||
|
|
||||||
|
# while True:
|
||||||
|
# print(get_temperature())
|
||||||
|
# time.sleep(1)
|
||||||
|
|
||||||
|
global GPIO
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
import time
|
import time
|
||||||
|
|
||||||
def get_temperature():
|
GPIO_TRIGGER = 18
|
||||||
i2c = busio.I2C(board.SCL, board.SDA)
|
GPIO_ECHO = 24
|
||||||
bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c, address=0x76)
|
GPIO.setup(GPIO_TRIGGER, GPIO.OUT)
|
||||||
return bmp280.temperature
|
GPIO.setup(GPIO_ECHO, GPIO.IN)
|
||||||
|
|
||||||
while True:
|
def get_water_level():
|
||||||
print(get_temperature())
|
GPIO.output(GPIO_TRIGGER, True)
|
||||||
time.sleep(1)
|
time.sleep(0.00001)
|
||||||
|
GPIO.output(GPIO_TRIGGER, False)
|
||||||
|
|
||||||
|
startTime = time.time()
|
||||||
|
StopTime = time.time()
|
||||||
|
|
||||||
|
while GPIO.input(GPIO_ECHO) == 0:
|
||||||
|
startTime = time.time()
|
||||||
|
while GPIO.input(GPIO_ECHO) == 1:
|
||||||
|
StopTime = time.time()
|
||||||
|
|
||||||
|
TimeElapsed = StopTime - startTime
|
||||||
|
distance = (TimeElapsed * 34300) / 2
|
||||||
|
|
||||||
|
return distance
|
||||||
|
|
||||||
|
print(get_water_level())
|
Loading…
Reference in New Issue