Last active
June 13, 2017 11:51
-
-
Save raspberrytipsnl/2368a3679e4c5419b2fa0fa8280bc1ab to your computer and use it in GitHub Desktop.
TCRT5000 tracking sensor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# TCRT5000 tracking sensor | |
# https://raspberrytips.nl/tcrt5000 | |
import RPi.GPIO as GPIO | |
TrackingPin = 11 | |
def setup(): | |
GPIO.setmode(GPIO.BOARD) | |
GPIO.setup(TrackingPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) | |
def loop(): | |
while True: | |
if GPIO.input(TrackingPin) == GPIO.LOW: | |
# Detectie wit oppervalk (of voorwerp bij sensor) | |
print '[wit | object]' | |
else: | |
# detectie zwart oppervlak (of geen voorwerp bij sensor) | |
print '[zwart | geen object]' | |
def destroy(): | |
GPIO.cleanup() | |
if __name__ == '__main__': | |
setup() | |
try: | |
loop() | |
except KeyboardInterrupt: | |
destroy() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment