라즈베리파이 Ultra 예제
2019. 9. 5. 11:27
Programing/Raspberry Pi)
import RPi.GPIO as gpio
import time
TRIGER = 24
ECHO = 23
gpio.setmode(gpio.BCM)
gpio.setup(TRIGER, gpio.OUT)
gpio.setup(ECHO, gpio.IN)
startTime = time.time()
try:
while True:
gpio.output(TRIGER, gpio.LOW)
time.sleep(0.1)
gpio.output(TRIGER, gpio.HIGH)
time.sleep(0.00002)
gpio.output(TRIGER, gpio.LOW)
while gpio.input(ECHO) == gpio.LOW:
startTime = time.time()
while gpio.input(ECHO) == gpio.HIGH:
startTime = time.time()
perio = endTime - startTime
dist1 = round(period * 1000000 / 58, 2)
dist2 = round(period * 17241, 2)
print ('Dist1', dist1, 'cm', ', Dist2', dist2, 'cn')
except:
gpio.cleanup()
'Programing > Raspberry Pi)' 카테고리의 다른 글
Raspberry Pi - OpenCV 설치 (0) | 2019.12.23 |
---|---|
TCP Rasspberry Pi Python and Android Client (0) | 2019.09.21 |
라즈베리파이, LED와 초음파센서 DB저장 (0) | 2019.09.07 |
라즈베리파이 Python [초음파센서, LED. 접근하면 Right On] (0) | 2019.09.05 |
라즈베리파이 LED예제 (0) | 2019.09.05 |