Skip to content

Instantly share code, notes, and snippets.

@takakabe
Created September 5, 2017 09:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takakabe/f50905d70b8a1485d512dd6c92a869aa to your computer and use it in GitHub Desktop.
Save takakabe/f50905d70b8a1485d512dd6c92a869aa to your computer and use it in GitHub Desktop.
RaspberryPi
#!/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