0% found this document useful (0 votes)
9 views3 pages

CVSFSFGSG

This document contains code to control LEDs and motors connected to a Raspberry Pi. It imports Tkinter and GPIO libraries to create a GUI with buttons to control the direction and speed of two motors by changing their PWM duty cycles. It also includes a scale widget to control the brightness of an LED by changing its PWM duty cycle. When the buttons are pressed, callbacks define the GPIO pin states to move the motors in different directions (forward, backward, left, right) or turn them off.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

CVSFSFGSG

This document contains code to control LEDs and motors connected to a Raspberry Pi. It imports Tkinter and GPIO libraries to create a GUI with buttons to control the direction and speed of two motors by changing their PWM duty cycles. It also includes a scale widget to control the brightness of an LED by changing its PWM duty cycle. When the buttons are pressed, callbacks define the GPIO pin states to move the motors in different directions (forward, backward, left, right) or turn them off.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

from tkinter import *

from gpiozero import LED, PWMLED

root = Tk()
root.title("Gestion GPIO")
root.geometry("540x260")
root.minimize(480,260)
root.config(background = '#C9V3AB')

frame = Frame(root, bg = '#C9V3AB')


frame.pack(expand = YES)

led_1 = Button(frame, text = "Alumer LED", font = ("Courrier", 14),bg = 'white', fg


= '#C9V3AB')
led_1.pack(pady = 5,fill = x)

led_2 = Button(frame, text = "Eteindre LED", font = ("Courrier", 14),bg = 'white',


fg = '#C9V3AB')
led_2.pack(pady = 5,fill = x)

echelle = Scale(frame, from_ = 0, to = 1, orient = HORIZONTAL, resolution =


0.1,tickinterval = 0.1, length = 350
label = 'Intensite lumineuse | PWM', bg = 'white', fg = '#C9C3AB')
echelle.pack(pady = 5,fill = x)

root.mainloop()

from tkinter import *


import RPi.GPIO as GPIO

EnaA = 2
In1A = 3
In2A = 4

EnaB = 17
In1B = 22
In2B = 27

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

GPIO.setup(EnaA, GPIO.OUT)
GPIO.setup(In1A, GPIO.OUT)
GPIO.setup(In2A, GPIO.OUT)
GPIO.setup(EnaB, GPIO.OUT)
GPIO.setup(In1B, GPIO.OUT)
GPIO.setup(In2B, GPIO.OUT)

pwm1 = GPIO.PWM(EnaA, 100)


pwm1.start(0)
pwm2 = GPIO.PWM(EnaB, 100)
pwm2.start(0)

def light(event):
x = echelle.get()
print(x)
def arriere():
GPIO.output(In1A, GPIO.HIGH)
GPIO.output(In2A, GPIO.LOW)
pwm1.ChangeDutyCycle(80)
GPIO.output(In1B, GPIO.LOW)
GPIO.output(In2B, GPIO.HIGH)
pwm2.ChangeDutyCycle(80)

def droite():
print('droite')
GPIO.output(In1A, GPIO.HIGH)
GPIO.output(In2A, GPIO.LOW)
pwm1.ChangeDutyCycle(60)
GPIO.output(In1B, GPIO.LOW)
GPIO.output(In2B, GPIO.HIGH)
pwm2.ChangeDutyCycle(80)#

def gauche():
print('gauche')
GPIO.output(In1A, GPIO.HIGH)
GPIO.output(In2A, GPIO.LOW)
pwm1.ChangeDutyCycle(80)
GPIO.output(In1B, GPIO.LOW)
GPIO.output(In2B, GPIO.HIGH)
pwm2.ChangeDutyCycle(60)

def arret():
GPIO.output(In1A, GPIO.HIGH)
GPIO.output(In2A, GPIO.LOW)
pwm1.ChangeDutyCycle(0)
GPIO.output(In1B, GPIO.LOW)
GPIO.output(In2B, GPIO.HIGH)
pwm2.ChangeDutyCycle(0)

def avant():
GPIO.output(In1A, GPIO.LOW)
GPIO.output(In2A, GPIO.HIGH)
pwm1.ChangeDutyCycle(80)
GPIO.output(In1B, GPIO.HIGH)
GPIO.output(In2B, GPIO.LOW)
pwm2.ChangeDutyCycle(80)

root = Tk()
root.title("Gestion GPIO")
root.geometry("540x260")
root.minsize(480, 260)
root.config(background='#C9C3AB')

frame = Frame(root, bg='#C9C3AB')


frame.pack(expand=YES)

led_1 = Button(frame, text="Avant", font=("Courrier", 14), command=avant,


bg='white', fg='#C9C3AB')
led_1.pack(pady=5, fill=X)

led_2 = Button(frame, text="Arriere", font=("Courrier", 14), command=arriere,


bg='white', fg='#C9C3AB')
led_2.pack(pady=5, fill=X)
led_3 = Button(frame, text="Aarret", font=("Courrier", 14), command=arret,
bg='white', fg='#C9C3AB')
led_3.pack(pady=5, fill=X)

led_4 = Button(frame, text="droite", font=("Courrier", 14), command=droite,


bg='white', fg='#C9C3AB')
led_4.pack(pady=5, fill=X)

led_5 = Button(frame, text="gauche", font=("Courrier", 14), command=gauche,


bg='white', fg='#C9C3AB')
led_5.pack(pady=5, fill=X)

echelle = Scale(frame, from_=0, to=1, orient=HORIZONTAL, resolution=0.1,


tickinterval=0.1, length=350,
label='Intensite lumineuse | PWM', command=light, bg='white',
fg='#C9C3AB')
echelle.pack(pady=5, fill=X)

root.mainloop()

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy