Ultra(초음파) Python
2019. 12. 28. 09:15
Programing/Raspberry Pi)
# -*- coding: utf-8 -*-
import RPi.GPIO as gpio
import time
TRIGER = 12 #초음파 tring
ECHO = 16 #초음파 echo
# ____gipo 핀 세팅___#
gpio.cleanup()
gpio.setmode(gpio.BCM)
gpio.setup(TRIGER, gpio.OUT)
gpio.setup(ECHO,gpio.IN)
#초음파 함수
def Ultra():
global cnt_One, cnt_Tree, cnt_Two, dist1
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:
endTime = time.time()
period = endTime - startTime
dist1 = round(period * 1000000 / 58, 2)
print('Dist1', dist1, 'cm')
Ultra()
'Programing > Raspberry Pi)' 카테고리의 다른 글
Database Insert Python (0) | 2019.12.28 |
---|---|
Buzzer Python (0) | 2019.12.28 |
LED Python (0) | 2019.12.28 |
해커톤 2019 113조 서버 (0) | 2019.12.27 |
Raspberry Pi - OpenCV 설치 (0) | 2019.12.23 |