Created
September 5, 2017 09:18
-
-
Save takakabe/f50905d70b8a1485d512dd6c92a869aa to your computer and use it in GitHub Desktop.
RaspberryPi
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 | |
# -*- coding: utf-8 -*- | |
import RPi.GPIO as GPIO | |
import time | |
# 初期設定 | |
GPIO.setmode(GPIO.BCM) | |
# GPIO 15 をデジタル入力に設定 | |
GPIO.setup(15, GPIO.IN) | |
try: | |
# Ctrl-C 待ち | |
while True: | |
print "%s GPIO 15 is %d" % (time.strftime("%Y/%m/%d %H:%M:%S"), GPIO.input(15)) | |
if GPIO.input(15) == 1: | |
print "晴れています" | |
else: | |
print "雨だー" | |
time.sleep(1.0) | |
except: | |
print "interrupted" | |
finally: | |
GPIO.cleanup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment