Traveling in Blanquillo AND MORE
  • Home
  • Trips
    • 2020 >
      • 2020 Sierras
    • 2019 >
      • 2019 Crater Lake
      • 2019 Westside Regional Park
    • 2018 >
      • 2018 So.California
      • 2018 Colorado-Arizona
      • 2018 Banff-Jasper
      • 2018 Osoyoos, BC
    • 2017 >
      • 2017 Olympic
      • 2017 Channel Islands
      • 2017 Eclipse
    • 2016 >
      • 2016 Glacier-Yellowstone
      • 2016 Southwest
    • 2015 >
      • 2015 Bryce-Zion
      • 2015 Lava Beds
      • 2015 Bristlecone-Yosemite
      • 2015 July first trip
    • 2014 >
      • 2014 Utah
  • Camping Map
  • Our Escape
  • Radio and Hobbies
    • Christmas LED Display
    • SCRA Membership Meetings
    • Scripts for Growing Classes >
      • 2e-RGB-LED
      • 2f-RGB-LED-GUI
      • 2g-RGB-LED-GUI
      • 3a-thermometer.py
      • 3b-thermometer-plus
      • 4a_DHT_simpletest.py
      • 4b_DHT_send_temperature.py
      • 4c_DHT_send_temperature_LED.py
      • 4c_DHT_send_temp.service
      • 4d_DHT_send_temp_LED_OLED.py
    • Winlink for Field Day 2020
    • Antenna Analyzer Code
  • Links
  • Contact
  • Home
  • Trips
    • 2020 >
      • 2020 Sierras
    • 2019 >
      • 2019 Crater Lake
      • 2019 Westside Regional Park
    • 2018 >
      • 2018 So.California
      • 2018 Colorado-Arizona
      • 2018 Banff-Jasper
      • 2018 Osoyoos, BC
    • 2017 >
      • 2017 Olympic
      • 2017 Channel Islands
      • 2017 Eclipse
    • 2016 >
      • 2016 Glacier-Yellowstone
      • 2016 Southwest
    • 2015 >
      • 2015 Bryce-Zion
      • 2015 Lava Beds
      • 2015 Bristlecone-Yosemite
      • 2015 July first trip
    • 2014 >
      • 2014 Utah
  • Camping Map
  • Our Escape
  • Radio and Hobbies
    • Christmas LED Display
    • SCRA Membership Meetings
    • Scripts for Growing Classes >
      • 2e-RGB-LED
      • 2f-RGB-LED-GUI
      • 2g-RGB-LED-GUI
      • 3a-thermometer.py
      • 3b-thermometer-plus
      • 4a_DHT_simpletest.py
      • 4b_DHT_send_temperature.py
      • 4c_DHT_send_temperature_LED.py
      • 4c_DHT_send_temp.service
      • 4d_DHT_send_temp_LED_OLED.py
    • Winlink for Field Day 2020
    • Antenna Analyzer Code
  • Links
  • Contact
​# 2f-RGB-LED-GUI.py
# use GUI sliders to control LEDs
from tkinter import *
from gpiozero import PWMLED
import time

# Configure the GPIO pins
red=PWMLED(24)
green=PWMLED(23)
blue=PWMLED(18)

# Start Pulse Width Modulation (PWM) on the red, green and blue channels 
red.value = 1       # start at minimum brightness
green.value = 1     # value 0 to 1
blue.value = 1      # backwards because common anode

# group together all of the GUI code into a class called App
class App:
    
    # this function gets called when the app is created
    def __init__(self, master):
        # A frame holds the various GUI controls
        frame = Frame(master)
        frame.pack()
        
        # Create the labels and position them in a grid layout
        Label(frame, text='Red').grid(row=0, column=0)
        Label(frame, text='Green').grid(row=1, column=0)
        Label(frame, text='Blue').grid(row=2, column=0)
        
        # Create the sliders and position them in a grid layout
        # the 'command' attribute specifys a method to call when
        # a slider is moved
        scaleRed = Scale(frame, from_=0, to=100,
              orient=HORIZONTAL, command=self.updateRed)
        scaleRed.grid(row=0, column=1)
        scaleGreen = Scale(frame, from_=0, to=100,
              orient=HORIZONTAL, command=self.updateGreen)
        scaleGreen.grid(row=1, column=1)
        scaleBlue = Scale(frame, from_=0, to=100,
              orient=HORIZONTAL, command=self.updateBlue)
        scaleBlue.grid(row=2, column=1)

    # These methods called whenever a slider moves
    def updateRed(self, duty):
        # change the led brightness to match the slider
        red.value = 1-float(int(duty) / 100)

    def updateGreen(self, duty):
        green.value = 1-float(int(duty) / 100)
    
    def updateBlue(self, duty):
        blue.value = 1-float(int(duty) / 100)

# Set the GUI running, give the window a title, size and position
root = Tk()
root.wm_title('RGB LED Control')
app = App(root)
root.geometry("200x150+0+0")
try:
    root.mainloop()
finally:  
    print("Cleaning up")
    red.value = 1       # turn off LED when exiting
    green.value = 1
    blue.value = 1
Copyright © 2020 by Dornbush Web Design