-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask5.2C.py
More file actions
48 lines (38 loc) · 1.31 KB
/
Task5.2C.py
File metadata and controls
48 lines (38 loc) · 1.31 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
37
38
39
40
41
42
43
44
45
46
47
48
import tkinter as tk
import RPi.GPIO as GPIO
# Set up GPIO to standard BOARD numbering
GPIO.setmode(GPIO.BOARD)
# Define GPIO pins for LEDs
RED_PIN = 11
GREEN_PIN = 12
BLUE_PIN = 13
# Initialize GPIO pins for LEDs
GPIO.setup(RED_PIN, GPIO.OUT)
GPIO.setup(GREEN_PIN, GPIO.OUT)
GPIO.setup(BLUE_PIN, GPIO.OUT)
# Set up PWM for each LED
red_pwm = GPIO.PWM(RED_PIN, 100)
green_pwm = GPIO.PWM(GREEN_PIN, 100)
blue_pwm = GPIO.PWM(BLUE_PIN, 100)
# Start PWM with 0% duty cycle
red_pwm.start(0)
green_pwm.start(0)
blue_pwm.start(0)
# Function to update PWM duty cycle based on slider value
def update_pwm(slider_value, pwm):
duty_cycle = int(slider_value)
pwm.ChangeDutyCycle(duty_cycle)
# Create GUI window
root = tk.Tk()
root.title("LED Intensity Control")
# Create sliders for each LED
red_slider = tk.Scale(root, from_=0, to=100, orient=tk.HORIZONTAL, label="Red LED", command=lambda value: update_pwm(value, red_pwm)).pack()
green_slider = tk.Scale(root, from_=0, to=100, orient=tk.HORIZONTAL, label="Green LED", command=lambda value: update_pwm(value, green_pwm)).pack()
blue_slider = tk.Scale(root, from_=0, to=100, orient=tk.HORIZONTAL, label="Blue LED", command=lambda value: update_pwm(value, blue_pwm)).pack()
# Run the GUI
root.mainloop()
# Clean up GPIO
red_pwm.stop()
green_pwm.stop()
blue_pwm.stop()
GPIO.cleanup()