Skip to content

Instantly share code, notes, and snippets.

@jezman
Last active September 9, 2016 08:27
Show Gist options
  • Save jezman/c6f2186b38c648df8e66d2c6926dbc09 to your computer and use it in GitHub Desktop.
Save jezman/c6f2186b38c648df8e66d2c6926dbc09 to your computer and use it in GitHub Desktop.
RaspberryPi relay switch. 0 - NC, 1 - NO
#!/usr/bin/env python
import RPi.GPIO as GPIO
import sys
PIN = 4
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(PIN, GPIO.OUT)
def relay_off():
GPIO.output(PIN, False)
def relay_on():
GPIO.output(PIN, True)
def unknown():
print 'Unknow'
switch = {'0': relay_off, '1': relay_on}
switch.get(sys.argv[1], unknown)()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment