Skip to content

Instantly share code, notes, and snippets.

@elktros
Created February 28, 2018 12:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elktros/e98d4410fcb0fcfe279e0f8ad6cd9c3c to your computer and use it in GitHub Desktop.
Save elktros/e98d4410fcb0fcfe279e0f8ad6cd9c3c to your computer and use it in GitHub Desktop.
Python Script for controlling a Relay with Raspberry Pi.
import RPi.GPIO as GPIO
import time
in1 = 16
in2 = 18
GPIO.setmode(GPIO.BOARD)
GPIO.setup(in1, GPIO.OUT)
GPIO.setup(in2, GPIO.OUT)
GPIO.output(in1, False)
GPIO.output(in2, False)
try:
while True:
for x in range(5):
GPIO.output(in1, True)
time.sleep(0.1)
GPIO.output(in1, False)
GPIO.output(in2, True)
time.sleep(0.1)
GPIO.output(in2, False)
GPIO.output(in1,True)
GPIO.output(in2,True)
for x in range(4):
GPIO.output(in1, True)
time.sleep(0.05)
GPIO.output(in1, False)
time.sleep(0.05)
GPIO.output(in1,True)
for x in range(4):
GPIO.output(in2, True)
time.sleep(0.05)
GPIO.output(in2, False)
time.sleep(0.05)
GPIO.output(in2,True)
except KeyboardInterrupt:
GPIO.cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment