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

Merge remote-tracking branch 'origin'

parents 95e3d594 4d928832
Branches master
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
from ctypes.wintypes import RGB
from time import sleep
import RPi.GPIO as GPIO
from colour import Color
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 = 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)
# 0 - 225 for (r, g, b)
def setRGBColor(self, r, g, b):
r = 100 - (r / 225) * 100
g = 100 - (r / 225) * 100
b = 100 - (r / 225) * 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):
self.r.ChangeDutyCycle(int(rgb[0]))
self.g.ChangeDutyCycle(int(rgb[1]))
self.b.ChangeDutyCycle(int(rgb[2]))
print( r, g, b )
# 0 - 100 for colours module ( any error to use this code...)
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)
# GPIO.cleanup()
#led = RGBA(12,13,19)
# led.setRGB(Color(input("Enter Any Color...")).rgb) # Enter any color code to blink
# sleep(10)
# GPIO.cleanup()
led = RGBA(12, 13, 19)
while True:
for c in Color("rgb").range_to(Color("blue") ,100):
led.setRGB(c.rgb)
sleep(0.1)
for c in Color("blue").range_to(Color("red") ,100):
led.setRGB(c.rgb)
sleep(0.1)
\ No newline at end of file
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
import RPi.GPIO as GPIO
from time import sleep
#GPIO.cleanup()
GPIO.setmode(GPIO.BCM)
channel = [12, 13, 19]
for c in channel:
GPIO.setup(c, GPIO.OUT)
#GPIO.output(channel, GPIO.HIGH)
#GPIO.output(channel, GPIO.LOW)
try:
while True:
try:
i = input("Enter a number between 0-7...")
i = int(i)
if i < 8 or i >=8:
print("Invalid range of input... Try again...")
continue
rgb = format(i, '03b')
for i, c in enumerate(channel):
print(i, c, rgb[i])
GPIO.output(c, not bool(int(rgb[i])))
except ValueError:
print("Invalid Input, Try again...")
except KeyboardInterrupt:
GPIO.cleanup()
print("Quitting...")
\ No newline at end of file
......@@ -19,6 +19,10 @@ Check any syntax error cmd:
apachectl configtest
=> syntax ok
Raspberry pi cmd:
hostname -I = Show in connecting IP address.
pip show ( colour ) = Show colour packages details.
Any python packages installing to environment error:
sudo aptget install colour --break-system-packages
......
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