#!/usr/bin/python #-------------------------------------------------------# # # # Name: 8Relay.py # # Author: James Clarke, Pridopia. # # Website: http://www.pridopia.co.uk # # Date: 06 / 02 / 14 # # Version: 1.10 # # # #-------------------------------------------------------# # # Copyright 2013 Pridopia ( www.pridopia.co.uk ) # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: # # http://www.apache.org/licenses/LICENSE-2.0 # # http://www.pridopia.com/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIC, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either-express or implied. # See the License for the specific language governing permissions and # limitations under the License. # import os, sys, time import RPi.GPIO as GPIO Pins = [17, 18, 27, 22, 23, 24, 25, 4] Relays = [False, False, False, False, False, False, False, False] GPIO.setmode(11) for A in Pins: GPIO.setup(A, GPIO.OUT) GPIO.output(A, 0) def Toggle(Relay): Cur = Relays[Relay] print Relays[Relay] Relays[Relay] = not Cur GPIO.output(Pins[Relay-1], not Cur) return Choice = "True" while Choice: os.system("clear") for A, B in enumerate(Relays): if B: B = " ON" else: B = "OFF" print "Relay {} ({}) [{}]".format(A+1, Pins[A], B) try: Choice = int(raw_input("(1-8) >")) if Choice >= 1 and Choice < 9: Toggle(Choice-1) except: print "Something Failed." time.sleep(0.5)