Guest User

Untitled

a guest
Jul 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. import tkinter as tk
  2. import RPi.GPIO as GPIO
  3. import time
  4. GPIO.setwarnings(False)
  5. GPIO.setmode(GPIO.BOARD)
  6. TRIGPIN = 11
  7. ECHO = 15
  8.  
  9. print ("Distance Measurement In Progress")
  10. GPIO.setup(TRIGPIN,GPIO.OUT)
  11. GPIO.setup(ECHO, GPIO.IN, pull_up_down= GPIO.PUD_DOWN)
  12.  
  13. root = tk.Tk()
  14. root.title("Calculating Distance")
  15.  
  16. GPIO.output(TRIGPIN, False)
  17. print ("Delay for sensor stability")
  18. time.sleep(2)
  19. GPIO.output(TRIGPIN, True)
  20. time.sleep(0.00001)
  21. GPIO.output(TRIGPIN, False)
  22. while GPIO.input(ECHO)==0:
  23. pulse_start= 0
  24. pulse_start= time.time()
  25. while GPIO.input(ECHO)==1:
  26. pulse_end= 0
  27. pulse_end= time.time()
  28. duration = pulse_end-pulse_start
  29.  
  30. distance = duration * 34029
  31. distance = distance / 2
  32. distance = round(distance, 2)
  33. print ("Distance:",distance,"cm")
  34.  
  35.  
  36. label = tk.Label(root,width=40, fg="yellow" , bg = "purple")
  37. label.config(font=("Courier", 36))
  38. label.config(text=str(distance))
  39. label.pack()
  40. button = tk.Button(root, text='Stop', width=50, command=root.destroy)
  41. button.pack()
  42. root.mainloop()
  43. GPIO.cleanup()
Add Comment
Please, Sign In to add comment