# 2g-RGB-LED-GUI.py
# 2020-06-20 revised for common anode configure option
# use GUI sliders to control LEDs
# to install guizero: $ pip3 install guizero
from guizero import App, Slider, Text
from gpiozero import PWMLED
#import time
# define methods to change LED brightness
def update_red(duty):
red.value = (float(duty)/100)
# change the led brightness to match the slider
def update_green(duty):
green.value = (float(duty)/100)
def update_blue(duty):
blue.value = (float(duty)/100)
# Configure the GPIO pins
red=PWMLED(24,False) # False because common anode
green=PWMLED(23,False)
blue=PWMLED(18,False)
# Start Pulse Width Modulation (PWM) on the red, green and blue channels
red.value = 0 # start at minimum brightness
green.value = 0
blue.value = 0
# create GUI and name it app
app = App(title='RGB LED Control', layout='grid')
# create labels for sliders and text
red_label = Text(app, text='Red', grid=[0,0])
green_label = Text(app, text='Green', grid=[0,1])
blue_label = Text(app, text='Blue', grid=[0,2])
stop_label = Text(app, text='use ther upper right X to stop script', grid=[0,3,2,1])
# create sliders
red_scale = Slider(app, grid=[1,0], command=update_red)
green_scale = Slider(app, grid=[1,1], command=update_green)
blue_scale = Slider(app, grid=[1,2], command=update_blue)
#size and position the GUI
app.tk.geometry("300x200+300+300")
# display the sliders and get values
try:
app.display()
finally:
print("Cleaning up")
red.value = 0 # turn off LED when exiting
green.value = 0
blue.value = 0
# 2020-06-20 revised for common anode configure option
# use GUI sliders to control LEDs
# to install guizero: $ pip3 install guizero
from guizero import App, Slider, Text
from gpiozero import PWMLED
#import time
# define methods to change LED brightness
def update_red(duty):
red.value = (float(duty)/100)
# change the led brightness to match the slider
def update_green(duty):
green.value = (float(duty)/100)
def update_blue(duty):
blue.value = (float(duty)/100)
# Configure the GPIO pins
red=PWMLED(24,False) # False because common anode
green=PWMLED(23,False)
blue=PWMLED(18,False)
# Start Pulse Width Modulation (PWM) on the red, green and blue channels
red.value = 0 # start at minimum brightness
green.value = 0
blue.value = 0
# create GUI and name it app
app = App(title='RGB LED Control', layout='grid')
# create labels for sliders and text
red_label = Text(app, text='Red', grid=[0,0])
green_label = Text(app, text='Green', grid=[0,1])
blue_label = Text(app, text='Blue', grid=[0,2])
stop_label = Text(app, text='use ther upper right X to stop script', grid=[0,3,2,1])
# create sliders
red_scale = Slider(app, grid=[1,0], command=update_red)
green_scale = Slider(app, grid=[1,1], command=update_green)
blue_scale = Slider(app, grid=[1,2], command=update_blue)
#size and position the GUI
app.tk.geometry("300x200+300+300")
# display the sliders and get values
try:
app.display()
finally:
print("Cleaning up")
red.value = 0 # turn off LED when exiting
green.value = 0
blue.value = 0