Skip to content
Snippets Groups Projects
Commit 93e8c77b authored by ANTO SAGAYA JUSTIN R's avatar ANTO SAGAYA JUSTIN R :speech_balloon:
Browse files

rgb

parent 2659469a
No related branches found
No related tags found
No related merge requests found
from time import sleep
import RPi.GPIO as GPIO
class RGBA():
def __init__(self, r, g, b):
GPIO.setmode(GPIO.BCM)
channel = [r, g, b]
for c in channel:
GPIO.setup(c, GPIO.OUT)
self.r = GPIO.PWM (r, 120) # channel = 12 frequency = 60Hz
self.g = GPIO.PWM (g, 120) # channel = 13 frequency = 60Hz
self.b = GPIO.PWM (b, 120) # channel = 19 frequency = 60Hz
self.r.start(0)
self.g.start(0)
self.b.start(0)
# 0 -255 for r, g, b
def setColor(self, r, g, b):
r = 100 - ( r / 255 ) * 100
g = 100 - ( g / 255 ) * 100
b = 100 - ( b / 255 ) * 100
print(r, g, b)
self.r.ChangeDutyCycle(r)
self.g.ChangeDutyCycle(g)
self.b.ChangeDutyCycle(b)
led = RGBA (12, 13, 19)
led.setColor ( 70, 34, 84 )
sleep(3)
GPIO.cleanup()
\ No newline at end of file
......@@ -12,6 +12,7 @@ class RGBA():
self.r = GPIO.PWM(r, 120) # channel = 12 frequency = 60Hz
self.g = GPIO.PWM(g, 120) # channel = 12 frequency = 60Hz
self.b = GPIO.PWM(b, 120) # channel = 12 frequency = 60Hz
self.r.start(0)
self.g.start(0)
self.b.start(0)
......@@ -36,15 +37,16 @@ class RGBA():
print( r, g, b )
# 0 - 100 for colours module ( any error to use this code...)
''' def setRGB(self, rgb):
def setRGB(self, rgb):
r = abs(rgb[0] * 100 - 100 )
g = abs(rgb[1] * 100 - 100 )
b = abs(rgb[2] * 100 - 100 )
print(r, g, b)
self.r.ChangeDutyCycle(int(r))
self.g.ChangeDutyCycle(int(g))
self.b.ChangeDutyCycle(int(b))
'''
# led = RGBA(12,13,19)
# led.setRGBColor(255,0,0) # type any color code to blink
# sleep(10)
......
from time import sleep
import RPi.GPIO as GPIO
from colour import Color
import math
class RGBA():
def __init__(self, r, g, b):
GPIO.setmode(GPIO.BCM)
channel = [r, g, b]
for c in channel:
GPIO.setup(c, GPIO.OUT)
self.r = GPIO.PWM (r, 120) # channel = 12 frequency = 60Hz
self.g = GPIO.PWM (g, 120) # channel = 13 frequency = 60Hz
self.b = GPIO.PWM (b, 120) # channel = 19 frequency = 60Hz
self.r.start(0)
self.g.start(0)
self.b.start(0)
# 0 -255 for r, g, b
def setRGBColor(self, r, g, b):
r = 100 - ( r / 255 ) * 100
g = 100 - ( g / 255 ) * 100
b = 100 - ( b / 255 ) * 100
print(r, g, b)
self.r.ChangeDutyCycle(int(r))
self.g.ChangeDutyCycle(int(g))
self.b.ChangeDutyCycle(int(b))
# 0 - 100 ( For colours module )
def setRGB(self, rgb):
r = abs (rgb[0] * 100 - 100 )
g = abs (rgb[1] * 100 - 100 )
b = abs (rgb[2] * 100 - 100 )
print(r, g, b)
self.r.ChangeDutyCycle(int(r))
self.g.ChangeDutyCycle(int(g))
self.b.ChangeDutyCycle(int(b))
led = RGBA (12, 13, 19)
while True:
try:
led.setRGB(Color(input("Enter Any Color: ")).rgb)
except KeyboardInterrupt:
# Handle the cleanup here
GPIO.cleanup() # Reset the GPIO pins
print("Cleaned up GPIO...")
break
# finally:
# print("Exit the Loops...")
\ No newline at end of file
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment