-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathled_gui.py
49 lines (38 loc) · 1.19 KB
/
led_gui.py
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
49
import tkinter as tk
from tkinter import Radiobutton
import RPi.GPIO as GPIO
# GPIO setup
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
GPIO.setup(27, GPIO.OUT)
GPIO.setup(22, GPIO.OUT)
# Function to turn on LEDs
def turn_on_led():
led = selected_led.get()
GPIO.output(17, GPIO.LOW)
GPIO.output(27, GPIO.LOW)
GPIO.output(22, GPIO.LOW)
if led == "Red":
GPIO.output(17, GPIO.HIGH)
elif led == "Green":
GPIO.output(27, GPIO.HIGH)
elif led == "Blue":
GPIO.output(22, GPIO.HIGH)
# GUI setup
root = tk.Tk()
root.title("LED Control")
selected_led = tk.StringVar()
selected_led.set("Red")
radiobutton_red = Radiobutton(root, text="Red", variable=selected_led, value="Red")
radiobutton_red.pack(anchor=tk.W)
radiobutton_green = Radiobutton(root, text="Green", variable=selected_led, value="Green")
radiobutton_green.pack(anchor=tk.W)
radiobutton_blue = Radiobutton(root, text="Blue", variable=selected_led, value="Blue")
radiobutton_blue.pack(anchor=tk.W)
button = tk.Button(root, text="Turn On LED", command=turn_on_led)
button.pack()
exit_button = tk.Button(root, text="Exit", command=root.quit)
exit_button.pack()
root.mainloop()
# Clean up GPIO
GPIO.cleanup()