Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM) # 初期設定
GPIO.setup(15,GPIO.OUT) # 出力設定
GPIO.setup(14,GPIO.IN) # 入力設定
# タクトスイッチの状態をもとに判定する
#!/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) # 入力設定
@takakabe
takakabe / tact_switch_led.py
Last active August 21, 2017 14:21
RaspberryPi
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import RPi.GPIO as GPIO
from time import sleep
######################
# 関数 my_callback
######################
def my_callback(channnel):
@takakabe
takakabe / pre_set_resist.py
Created August 25, 2017 11:49
RaspberryPi
# -*- coding: utf-8 -*-
import RPi.GPIO as GPIO
from time import sleep
###############################
# MCP3208からSPI通信で12ビットのデジタル値を取得。0から7の8チャンネル使用可
###############################
def readadc(adcnum, clockpin, mosipin, misopin, cspin):
if adcnum > 7 or adcnum < 0:
return -1
@takakabe
takakabe / tactswitch_camera.py
Last active September 3, 2017 12:37
RaspberryPi
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import RPi.GPIO as GPIO
from time import sleep
import subprocess
######################
# 関数 my_callback
######################
@takakabe
takakabe / rain_sensor.py
Created September 5, 2017 09:18
RaspberryPi
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import RPi.GPIO as GPIO
import time
# 初期設定
GPIO.setmode(GPIO.BCM)
# GPIO 15 をデジタル入力に設定
@takakabe
takakabe / tactswitch_shutdown.py
Last active September 6, 2017 07:17
RaspberryPi
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import RPi.GPIO as GPIO
from time import sleep
import subprocess
######################
# 関数 my_callback
######################
@takakabe
takakabe / light_sensor_led.py
Last active September 6, 2017 10:49
RaspberryPi
# -*- coding: utf-8 -*-
import RPi.GPIO as GPIO
from time import sleep
###############################
# ADコンバータからSPI通信で12ビットのデジタル値を取得。0から7の8チャンネル使用可
###############################
def readadc(adcnum, clockpin, mosipin, misopin, cspin):
if adcnum > 7 or adcnum < 0:
return -1
@takakabe
takakabe / remote_script.sh
Created September 13, 2017 10:19
ShellScript
#!/bin/bash
if [ "${REMOTEHOST}" ] ; then
echo "remote dayo"
else
echo "local dayo"
fi
exit 0
@takakabe
takakabe / DHT11.py
Last active September 21, 2017 12:31
RaspberryPi
import RPi.GPIO as GPIO
import time
#DHT11 connect to BCM_GPIO14
DHTPIN = 14
GPIO.setmode(GPIO.BCM)
MAX_UNCHANGE_COUNT = 100
STATE_INIT_PULL_DOWN = 1
STATE_INIT_PULL_UP = 2
STATE_DATA_FIRST_PULL_DOWN = 3
STATE_DATA_PULL_UP = 4