Scale1 = Scale(Gui, from_=0, to=100, orient = HORIZONTAL, resolution = 1, command = ChangePWM) Scale1.grid(row=1,column=2)
PwmValue = GPIO.PWM(LED, 5000) PwmValue.start(0)
def ChangePWM(self): PwmValue.ChangeDutyCycle(Scale1.get())
# ************************************************************************** # # **** **** # # *********** Code Designed by www.TheEngineeringProjects.com ************** # # **** **** # # ****************** How to Create a GUI in Raspberry Pi 3 ***************** # # **** **** # # ************************************************************************** # # Importing Libraries import RPi.GPIO as GPIO import time from tkinter import * import tkinter.font # Libraries Imported successfully # Raspberry Pi 3 Pin Settings LED = 12 # pin12 GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) # We are accessing GPIOs according to their physical location GPIO.setup(LED, GPIO.OUT) # We have set our LED pin mode to output GPIO.output(LED, GPIO.LOW) # When it will start then LED will be OFF PwmValue = GPIO.PWM(LED, 5000) PwmValue.start(0) # Raspberry Pi 3 Pin Settings # tkinter GUI basic settings Gui = Tk() Gui.title("GUI in Raspberry Pi 3") Gui.config(background= "#0080FF") Gui.minsize(800,300) Font1 = tkinter.font.Font(family = 'Helvetica', size = 24, weight = 'bold') # tkinter simple GUI created def ledON(): GPIO.output(LED, GPIO.HIGH) # led on Text2 = Label(Gui,text=' ON ', font = Font1, bg = '#0080FF', fg='green', padx = 0) Text2.grid(row=0,column=1) def ledOFF(): GPIO.output(LED, GPIO.LOW) # led off Text2 = Label(Gui,text='OFF', font = Font1, bg = '#0080FF', fg='red', padx = 0) Text2.grid(row=0,column=1) def ChangePWM(self): PwmValue.ChangeDutyCycle(Scale1.get()) Text1 = Label(Gui,text='LED Status:', font = Font1, fg='#FFFFFF', bg = '#0080FF', padx = 50, pady = 50) Text1.grid(row=0,column=0) Text2 = Label(Gui,text='OFF', font = Font1, fg='#FFFFFF', bg = '#0080FF', padx = 0) Text2.grid(row=0,column=1) Button1 = Button(Gui, text=' LED ON', font = Font1, command = ledON, bg='bisque2', height = 1, width = 10) Button1.grid(row=1,column=0) Button2 = Button(Gui, text=' LED OFF', font = Font1, command = ledOFF, bg='bisque2', height = 1, width = 10) Button2.grid(row=1,column=1) Scale1 = Scale(Gui, from_=0, to=100, orient = HORIZONTAL, resolution = 1, command = ChangePWM) Scale1.grid(row=1,column=2) Text3 = Label(Gui,text='www.TheEngineeringProjects.com', font = Font1, bg = '#0080FF', fg='#FFFFFF', padx = 50, pady = 50) Text3.grid(row=2,columnspan=2) Gui.mainloop()
[dt_default_button link="https://www.theengineeringprojects.com/RaspberryPi3/How to Create PWM in Raspberry Pi 3.rar" button_alignment="default" animation="fadeIn" size="medium" default_btn_bg_color="" bg_hover_color="" text_color="" text_hover_color="" icon="fa fa-chevron-circle-right" icon_align="left"]Download PWM Pulse Code for Raspberry Pi 3[/dt_default_button]
JLCPCB – Prototype 10 PCBs for $2 (For Any Color)
China’s Largest PCB Prototype Enterprise, 600,000+ Customers & 10,000+ Online Orders Daily
How to Get PCB Cash Coupon from JLCPCB: https://bit.ly/2GMCH9w