Commit e43d4fe3 authored by Rajasingam kokilan's avatar Rajasingam kokilan

write

parent f87ea92f
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import time
import RPi.GPIO as GPIO
def ping():
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
trig_2 = 26
echo_2 = 19
while True:
# Echo
GPIO.setup(trig_2,GPIO.OUT) # Trigger
GPIO.setup(echo_2,GPIO.IN)
GPIO.output(trig_2, False)
time.sleep(1.5)
GPIO.output(trig_2, True)
time.sleep(0.001)
GPIO.output(trig_2, False)
start1 = time.time()
while GPIO.input(echo_2)==0:
start1 = time.time()
while GPIO.input(echo_2)==1:
stop1= time.time()
elapsed1 = stop1-start1
distancet1 = (elapsed1*34300)-0.5
distance1 = distancet1/2
elapsed1=round(elapsed1,6)
distance1 = round(distance1,0)
y=str(distance1)
x=str(elapsed1)
if distance1<5:
print("tank full open door")
elif distance1>8 and distance1<12:
print("Tank Is Approximately Half dont open door")
elif distance1>18 and distance1<21:
print("Tank Is Empty")
z=x+","+y+"\n"
print(z)
file='text.txt'
with open(file,'a') as filetowrite:
filetowrite.write(z)
filetowrite.close()
GPIO.cleanup()
return distance1
while True:
ping()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment