관리 메뉴

안까먹을라고 쓰는 블로그

[With Raspberry3] - GPIO 본문

Language/Python

[With Raspberry3] - GPIO

YawnsDuzin 2016. 7. 25. 16:53

 

반응형
import RPi.GPIO as GPIO
import time

print "Motion Sensor"


GPIO.setmode(GPIO.BCM)

#GPIO 23 - IN Set
GPIO.setup(23, GPIO.IN)

#GPIO 24 - OUT Set
GPIO.setup(24, GPIO.OUT)


OperationFlag = False

count = 0
DetectedFlag = 0
while True:
        # GPIO 24 - OUT Test
	if OperationFlag == False:
		OperationFlag = True
		GPIO.output(24, True)
		time.sleep(5)
	else:
		OperationFlag = False
		GPIO.output(24, False)
		time.sleep(5)

        # GPIO 23 - IN Test
	i = GPIO.input(23)
	if i == True:
		if DetectedFlag == 0:
			count += 1
			DetectedFlag = 1
			print('Motion Detected = ' + str(count))
			#time.sleep(5)
	else:
		DetectedFlag = 0
		
print "GPIO.cleanup()"
GPIO.cleanup()
 
반응형

'Language > Python' 카테고리의 다른 글

[ Python ] - GUI Program  (0) 2016.08.22
Flask  (0) 2016.08.16
[ Python ] 교육링크  (0) 2016.06.27
[ Python ] Windows xx 설치  (0) 2016.06.07
[ Python ] MSSQL 연동  (0) 2016.06.03
Comments