| 12
 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
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 
 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
 
# Declaration des librairies
import os
import wiringpi2 as WR
from time import sleep
from random import randrange
from Tkinter import *
 
CLOCK = 27 # Pin 27 GPIO
DATA = 18 # Pin 18 GPIO
LATCH = 24 # Pin 24 GPIO
 
WR.wiringPiSetupGpio() # Configuration des pins
WR.pinMode(LATCH,1) # La pin 24 GPIO du Latch est en sortie
WR.pinMode(DATA,1) # La pin 18 GPIO de data est en sortie
WR.pinMode(CLOCK,1) # La pin 27 GPIO de clock est en sortie
 
 
def send_att(attn): # Fonction de calcul et de transmission des donnees
    if 0 <= attn < 31:
        WR.shiftOut(DATA,CLOCK,1,(int(attn)*2)) # Le 1 ou le 0 permet d'inverser l'ordre des bits
 
    elif attn < 63:
        WR.shiftOut(DATA,CLOCK,1,(((int(attn)-31)+32)*2)) # int(attn) evite l'erreur " unsuported operand type for -: 'str' and 'int' "
 
    elif attn < 93:
        WR.shiftOut(DATA,CLOCK,1,(((int(attn)-62)+96)*2))
 
    elif attn >= 93:
        attn = 93
    # end if
 
# end def
 
 
def Cursor(attn): # Fonction pour recuperer la valeur du curseur
    voie1 = slider1.get() # Voie 1 = Position du curseur
    send_att(voie1) # Appel de fonction avec attn = voie1
    WR.digitalWrite(LATCH,1) # LATCH ON
    WR.digitalWrite(LATCH,0) # LATCH OFF
    #~ print voie1
    # init taille carré
    size = 5
    # init hauteur de référence graphique
    h = graphique.winfo_reqheight() - 7 - size
    # init ordonnée y
    y = h * (1 - voie1 / slider1["to"])
    # init abscisse x
    x = graphique.winfo_reqwidth() - 2 - size
    # on représente la valeur par un carré
    graphique.create_rectangle(
        x, y, x+size, y+size,
        fill="red", outline="black", width=1, tag="dots",
    )
    # scrolling relatif
    graphique.move("dots", -size, 0)
 
# end def
 
 
# Creation de l'IHM
fenetre = Tk()
fenetre.title("Ways Command")
 
voie1 = IntVar() # Declaration des variables pour Scale apres Tk(). Evite l'erreur " 'NoneType' object has no attribute 'tk' "
attn = IntVar()
 
slider1 = Scale(
    fenetre,
    orient=HORIZONTAL,
    length=600,
    width=20,
    sliderlength=10,
    from_=0,
    to=93.5,
    tickinterval=10,
    resolution=5,
    variable=voie1,
    command=Cursor,
) # Choisir la valeur de la voie 1 avec le Scale
 
slider1.pack()
 
bouton_quitter = Button(fenetre,text="Quitter",bg='red',command=fenetre.destroy) # Boutton quitter
bouton_quitter.pack(side=LEFT,anchor="sw")
 
graphique = Canvas(fenetre,bg='white',height=150,width=200) # Ajouter un graphique qui affiche les variations du Scale
graphique.pack()
graphique.create_line(10,145,200,145,arrow=LAST) # Axe des abscisses
graphique.create_line(10,145,10,5,arrow=LAST) # Axe des ordonnées
pas = (175/8)
for t in range(1,9): # Graduations
    stx = 10 + t*pas
    graphique.create_line(stx,141,stx,149)
 
fenetre.mainloop()# Boucle principale | 
Partager