Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.