rgb led steuerung programmiert (rumpf)
This commit is contained in:
parent
4f67b16bb7
commit
478922e3d9
@ -87,6 +87,8 @@ def enterName():
|
||||
if event.type == KEYDOWN:
|
||||
if event.key == pygame.K_BACKSPACE:
|
||||
name = name[:-1]
|
||||
elif event.key == pygame.K_RETURN:
|
||||
return name
|
||||
else:
|
||||
name += event.unicode
|
||||
elif event.key == pygame.K_BACKSPACE:
|
||||
|
118
rgb_led.py
Normal file
118
rgb_led.py
Normal file
@ -0,0 +1,118 @@
|
||||
import signal, sys, time, os, RPi.GPIO as GPIO
|
||||
|
||||
|
||||
pin_red = 22
|
||||
pin_green = 18
|
||||
pin_blue = 16
|
||||
|
||||
|
||||
red = ""
|
||||
green = ""
|
||||
blue = ""
|
||||
|
||||
def exit_application():
|
||||
GPIO.cleanup()
|
||||
sys.exit()
|
||||
return
|
||||
|
||||
|
||||
def signal_handler(sig, frame):
|
||||
print('Programm exiting')
|
||||
exit_application()
|
||||
|
||||
|
||||
#signal handing for controlled exit via ctrl+c
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
|
||||
GPIO.setmode(GPIO.BOARD)
|
||||
|
||||
def led_init():
|
||||
global red,green,blue
|
||||
GPIO.setup(pin_red, GPIO.OUT)
|
||||
GPIO.setup(pin_green, GPIO.OUT)
|
||||
GPIO.setup(pin_blue, GPIO.OUT)
|
||||
|
||||
red = GPIO.PWM(pin_red, 100)
|
||||
red.ChangeDutyCycle(0)
|
||||
#red.ChangeFrequency(100)
|
||||
|
||||
blue = GPIO.PWM(pin_blue, 100)
|
||||
blue.ChangeDutyCycle(0)
|
||||
#blue.ChangeFrequency(100)
|
||||
|
||||
green = GPIO.PWM(pin_green, 100)
|
||||
green.ChangeDutyCycle(0)
|
||||
#green.ChangeFrequency(100)
|
||||
green.start(0)
|
||||
blue.start(0)
|
||||
red.start(0)
|
||||
|
||||
def fade_red(zeit):
|
||||
for i in range(10,70):
|
||||
print(i)
|
||||
red.ChangeDutyCycle(i)
|
||||
time.sleep(zeit)
|
||||
for i in range(0,60):
|
||||
print(i)
|
||||
red.ChangeDutyCycle(70-i)
|
||||
time.sleep(zeit)
|
||||
|
||||
def fade_blue(zeit):
|
||||
for i in range(10,70):
|
||||
print(i)
|
||||
blue.ChangeDutyCycle(i)
|
||||
time.sleep(zeit)
|
||||
for i in range(0,60):
|
||||
print(i)
|
||||
blue.ChangeDutyCycle(70-i)
|
||||
time.sleep(zeit)
|
||||
|
||||
|
||||
def fade_green(zeit):
|
||||
for i in range(10,70):
|
||||
print(i)
|
||||
green.ChangeDutyCycle(i)
|
||||
time.sleep(zeit)
|
||||
for i in range(0,60):
|
||||
print(i)
|
||||
green.ChangeDutyCycle(70-i)
|
||||
time.sleep(zeit)
|
||||
|
||||
|
||||
def change_green(amount):
|
||||
# takes an input from 0 to 255 and converts it to Duty Cycle
|
||||
global green
|
||||
factor = 100/255
|
||||
green.ChangeDutyCycle(amount*factor)
|
||||
|
||||
def change_blue(amount):
|
||||
# takes an input from 0 to 255 and converts it to Duty Cycle
|
||||
global blue
|
||||
factor = 100/255
|
||||
blue.ChangeDutyCycle(amount*factor)
|
||||
|
||||
def change_red(amount):
|
||||
# takes an input from 0 to 255 and converts it to Duty Cycle
|
||||
global red
|
||||
factor = 100/255
|
||||
red.ChangeDutyCycle(amount*factor)
|
||||
|
||||
def change_led_colour(red_amount,green_amount,blue_amount):
|
||||
global red,green,blue
|
||||
red.ChangeDutyCycle(red_amount)
|
||||
blue.ChangeDutyCycle(blue_amount)
|
||||
green.ChangeDutyCycle(green_amount)
|
||||
|
||||
|
||||
led_init()
|
||||
|
||||
|
||||
|
||||
|
||||
while True:
|
||||
change_led_colour(99,0,99)
|
||||
time.sleep(0.2)
|
||||
change_led_colour(0,99,99)
|
||||
time.sleep(0.2)
|
||||
change_led_colour(99,99,0)
|
||||
time.sleep(0.2)
|
Loading…
Reference in New Issue
Block a user