Skip to content

Instantly share code, notes, and snippets.

@takakabe
Last active August 21, 2017 12:50
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/20e18ac634552ce539b596802a696f1d to your computer and use it in GitHub Desktop.
Save takakabe/20e18ac634552ce539b596802a696f1d to your computer and use it in GitHub Desktop.
RaspberryPi
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM) # 初期設定
GPIO.setup(15,GPIO.OUT) # 出力設定
# pull_up_down=GPIO.PUD_DOWNでプルダウン抵抗を設定
GPIO.setup(14,GPIO.IN,pull_up_down=GPIO.PUD_DOWN) # 入力設定
# タクトスイッチの状態をもとに判定する
# 押す=HIGH はなす=LOW
while True:
if GPIO.input(14) == GPIO.HIGH:
GPIO.output(15,GPIO.HIGH) # LED点灯
else:
GPIO.output(15,GPIO.LOW) # LED消灯
GPIO.cleanup() # GPIO初期化
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment