| 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
 
 | # -*- coding: cp1252 -*-
import os # Declaration des librairies
import wiringpi2 as WR
from time import sleep
from Tkinter import *
from random import randrange
 
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
 
# 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 Slade
Slider1.pack()
 
bouton_quitter = Button(fenetre,text="Quittter",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,75,200,75,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,71,stx,79)
 
fenetre.mainloop()# Boucle principale | 
Partager