Skip to content

Commit

Permalink
Initial Release
Browse files Browse the repository at this point in the history
  • Loading branch information
alaub81 committed Nov 10, 2021
1 parent 63185a0 commit 147f435
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions rgbled.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/python3
# Import required Python libraries
import RPi.GPIO as GPIO
import time

# Set the Variables
# set red,green and blue pins
redPin = 22
greenPin = 27
bluePin = 17

# Configuration
# disable warnings (optional)
GPIO.setwarnings(False)
# Select GPIO Mode
GPIO.setmode(GPIO.BCM)
# set pins as outputs
GPIO.setup(redPin,GPIO.OUT)
GPIO.setup(greenPin,GPIO.OUT)
GPIO.setup(bluePin,GPIO.OUT)

# Functions
def turnOff():
GPIO.output(redPin,GPIO.LOW)
GPIO.output(greenPin,GPIO.LOW)
GPIO.output(bluePin,GPIO.LOW)
def white():
GPIO.output(redPin,GPIO.HIGH)
GPIO.output(greenPin,GPIO.HIGH)
GPIO.output(bluePin,GPIO.HIGH)
def red():
GPIO.output(redPin,GPIO.HIGH)
GPIO.output(greenPin,GPIO.LOW)
GPIO.output(bluePin,GPIO.LOW)
def green():
GPIO.output(redPin,GPIO.LOW)
GPIO.output(greenPin,GPIO.HIGH)
GPIO.output(bluePin,GPIO.LOW)
def blue():
GPIO.output(redPin,GPIO.LOW)
GPIO.output(greenPin,GPIO.LOW)
GPIO.output(bluePin,GPIO.HIGH)
def yellow():
GPIO.output(redPin,GPIO.HIGH)
GPIO.output(greenPin,GPIO.HIGH)
GPIO.output(bluePin,GPIO.LOW)
def purple():
GPIO.output(redPin,GPIO.HIGH)
GPIO.output(greenPin,GPIO.LOW)
GPIO.output(bluePin,GPIO.HIGH)
def lightBlue():
GPIO.output(redPin,GPIO.LOW)
GPIO.output(greenPin,GPIO.HIGH)
GPIO.output(bluePin,GPIO.HIGH)

# do the stuff
while True:
try:
print("Press CTRL+C to exit")
turnOff()
time.sleep(1)
white()
time.sleep(1)
red()
time.sleep(1)
green()
time.sleep(1)
blue()
time.sleep(1)
yellow()
time.sleep(1)
purple()
time.sleep(1)
lightBlue()
time.sleep(1)
except KeyboardInterrupt:
print("Goodbye!")
turnOff()
exit (0)
except :
print("An Error accured ... ")
time.sleep(1)
continue

0 comments on commit 147f435

Please sign in to comment.