From 93e8c77b2b6403a190b54efefcbe4f2dc0eae6c0 Mon Sep 17 00:00:00 2001
From: ANTO SAGAYA JUSTIN R
 <7411-justinmass2001@users.noreply.git.selfmade.ninja>
Date: Thu, 19 Sep 2024 08:05:17 +0000
Subject: [PATCH] rgb

---
 Raspberrypi/rgbcolor/255_valu.py              | 32 ++++++++++++
 .../{RGBsmoothcolor.py => rgbcolor/color.py}  |  6 ++-
 Raspberrypi/rgbcolor/input.py                 | 52 +++++++++++++++++++
 Raspberrypi/{ => rgbcolor}/type0-7color.py    |  0
 4 files changed, 88 insertions(+), 2 deletions(-)
 create mode 100644 Raspberrypi/rgbcolor/255_valu.py
 rename Raspberrypi/{RGBsmoothcolor.py => rgbcolor/color.py} (97%)
 create mode 100644 Raspberrypi/rgbcolor/input.py
 rename Raspberrypi/{ => rgbcolor}/type0-7color.py (100%)

diff --git a/Raspberrypi/rgbcolor/255_valu.py b/Raspberrypi/rgbcolor/255_valu.py
new file mode 100644
index 0000000..a9e4ad7
--- /dev/null
+++ b/Raspberrypi/rgbcolor/255_valu.py
@@ -0,0 +1,32 @@
+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
diff --git a/Raspberrypi/RGBsmoothcolor.py b/Raspberrypi/rgbcolor/color.py
similarity index 97%
rename from Raspberrypi/RGBsmoothcolor.py
rename to Raspberrypi/rgbcolor/color.py
index 5b2ed9a..fd508cc 100644
--- a/Raspberrypi/RGBsmoothcolor.py
+++ b/Raspberrypi/rgbcolor/color.py
@@ -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)
diff --git a/Raspberrypi/rgbcolor/input.py b/Raspberrypi/rgbcolor/input.py
new file mode 100644
index 0000000..66ed35b
--- /dev/null
+++ b/Raspberrypi/rgbcolor/input.py
@@ -0,0 +1,52 @@
+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
diff --git a/Raspberrypi/type0-7color.py b/Raspberrypi/rgbcolor/type0-7color.py
similarity index 100%
rename from Raspberrypi/type0-7color.py
rename to Raspberrypi/rgbcolor/type0-7color.py
-- 
GitLab