Make GIU interface for Control LED in Raspberry pi
You want to make an application to run on the Raspberry Pi that has a button for turning things on and off. Today I show you How to Make GIU interface for Control LED in Raspberry pi Step bt step Complet Process.Required Component connect LED Raspberry Pi :
1.Raspberry pi 5. 5mm LED
This book will help you to gain more knowledge of Raspberry pi Software and Hardware Problems and Solutions
Raspberry Pi Cookbook
Circuit diagram connects LED Raspberry Pi:
shows how you can wire this LED using a solderless breadboard and male-to-female jumper leadsConnecting an LED to a Raspberry Pi
Code GIU LED Raspberry pi:
from tkinter import * import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setup(12, GPIO.OUT) class App: def __init__(self, master): frame = Frame(master) frame.pack() self.check_var = BooleanVar() check = Checkbutton(frame, text='LED ON Or OFF', command=self.update, variable=self.check_var, onvalue=True, offvalue=False) check.grid(row=1) def update(self): GPIO.output(12, self.check_var.get()) root = Tk() root.wm_title('On / Off Switch') app = App(root) root.geometry("200x100+0+0") root.mainloop()When you run this Code you can see like this interface and Python program that uses a checkbox to turn the GPIO pin on and off
Its initializer function creates a member variable called check_var that contains an instance of BooleanVar that is then supplied as
the variable option to the checkbox. The command option runs the update command every time such a change
occurs. The update function simply writes the value in check_var to the GPIO output.
No comments