-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5_2.py
More file actions
36 lines (28 loc) · 1.21 KB
/
5_2.py
File metadata and controls
36 lines (28 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from tkinter import *
import tkinter.font
from gpiozero import PWMLED
import RPi.GPIO
# Setup GPIO
RPi.GPIO.setmode(RPi.GPIO.BCM)
LED_PINS = {'red': 17, 'green': 27, 'blue': 22}
leds = {color: PWMLED(pin) for color, pin in LED_PINS.items()}
# Initialize main window
win = Tk()
win.title("LED Brightness Controller")
win.geometry("350x350") # Adjust size to fit sliders
myFont = tkinter.font.Font(family='Helvetica', size=12, weight="bold")
def update_led_brightness(value, led):
brightness = float(value) / 100 # Convert value to float and scale to 0-1
led.value = brightness
def close():
RPi.GPIO.cleanup()
win.destroy()
# Generate sliders and labels for each LED
for i, (color, led) in enumerate(leds.items()):
Label(win, text=f"{color.capitalize()} LED", font=myFont).grid(row=i*2, column=0, padx=10, pady=5)
slider = Scale(win, from_=0, to=100, orient=HORIZONTAL, command=lambda value, led=led: update_led_brightness(value, led))
slider.grid(row=i*2 + 1, column=0, padx=10, pady=5, sticky='ew')
exitButton = Button(win, text='Exit', font=myFont, command=close, bg='red', height=2, width=6)
exitButton.grid(row=2*len(leds), column=0, pady=10)
win.protocol("WM_DELETE_WINDOW", close)
win.mainloop()