other test

Signed-off-by: Ebbe Baß <ebbe@ping-mee.de>
master
Ebbe Baß 2022-07-11 01:27:51 +02:00
parent a502835062
commit b136496d23
1 changed files with 39 additions and 39 deletions

78
test.py
View File

@ -1,44 +1,44 @@
# import board
# import busio
# 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 board
import busio
import adafruit_bmp280
import time
GPIO.setmode(GPIO.BCM)
def get_temperature():
i2c = busio.I2C(board.SCL, board.SDA)
bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c, address=0x76)
return bmp280.temperature
GPIO_TRIGGER = 18
GPIO_ECHO = 24
GPIO.setup(GPIO_TRIGGER, GPIO.OUT)
GPIO.setup(GPIO_ECHO, GPIO.IN)
while True:
print(get_temperature())
time.sleep(1)
def get_water_level():
GPIO.output(GPIO_TRIGGER, True)
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
# global GPIO
# import RPi.GPIO as GPIO
# import time
print(get_water_level())
# GPIO.setmode(GPIO.BCM)
# GPIO_TRIGGER = 18
# GPIO_ECHO = 24
# GPIO.setup(GPIO_TRIGGER, GPIO.OUT)
# GPIO.setup(GPIO_ECHO, GPIO.IN)
# def get_water_level():
# GPIO.output(GPIO_TRIGGER, True)
# 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())