Created
February 21, 2015 07:19
-
-
Save miaoski/47aed5954f38871cc58b to your computer and use it in GitHub Desktop.
Simple GPIO for RPi2 + relay
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
# -*- coding: utf8 -*- | |
# sudo python relay.py | |
import RPi.GPIO as GPIO | |
GPIO.setmode(GPIO.BOARD) | |
GPIO.setup(38, GPIO.OUT) | |
GPIO.setup(40, GPIO.OUT) | |
print 'Usage:' | |
print ' 1 on / 1 off / 2 on / 2 off' | |
gpios = {'1': 38, '2': 40} | |
outs = {'on': 1, 'off': 0} | |
while True: | |
x = raw_input('> ') | |
xs = x.strip().split() | |
if xs[0] in gpios and xs[1] in outs: | |
GPIO.output(gpios[xs[0]], outs[xs[1]]) | |
else: | |
print 'Invalid command' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment