| 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
 
 |  
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import time
import tkinter
from tkinter import *
 
 
valueADCx= []
valadc=[]
def ADC ():
    global  valueADC, valueADCx, valadc
 
    #Initialisation du deque
    SIZE = 10
    fil = deque(maxlen=SIZE)
 
    for i in range(10):
        vals= adc.read_adc(1, gain=GAIN)
        fil.appendleft(vals)
        if len(fil) == SIZE:  #Une fois remplie, calcul de la moyenne
            valueADCx= sum(fil)/SIZE
            valueADCy= valueADCx 
            valueADC.set('%6.1f'%valueADCy)
            time.sleep(0.5)
 
    label9.after(100,ADC)
    #Création variable qui sera affiché dans fichier texte
    valadc.append(round(valueADCx,1))
 
 
def animate ():
    fig = plt.figure()
    ax = fig.add_subplot(1,1,1)
 
    #temps abscisses, comment récuperer?
    x=
    y=valadc.append(round(valueADCx,1))
    xlabel("Temps (s)")
    ylabel("Valeurs ADC")
    xar = []
    yar = []
    #Affichage continu valeurs
    xar.append(int(x))
    yar.append(int(y))
    ax.plot(xar,yar)
    #Afficher valeur toutes les 0.5s
    ani = animation.FuncAnimation(fig, animate, interval=500)
    figure.canvas.draw()
    plt.show()
 
 
fenetre = Tk()
 
#Bouton Afficher les valeurs du capteurs deplacement
bouton3=Button(frame1,text="ADC", command= ADC, padx=10, pady=10, width=10)
bouton3.config(font=('arial', 12, 'bold'))
bouton3.grid(row=2, column=1)
valueADC=StringVar()
label9=Label(frame1, textvariable=valueADC, width=12, height=2)
label9.config(font=('arial', 15, 'bold'))
label9.grid(row=2, column=2)
#label9.config(text=valueADC)
 
#Generation du graphique 
bouton2=Button(fenetre, text='Graphique', command=animate)
bouton2.grid(row=0,column=1)
 
 
# Création d'un widget Canvas (zone graphique)
Canevas = Canvas(fenetre)
Canevas.grid(row=0, column=2)
 
#Bouton quitter
bouton4=Button(fenetre,text="Quitter", command=fenetre.destroy,width=10, height=2, padx=10, pady=10)
bouton4.config(font=('arial', 12, 'bold'))
bouton4.grid(row=1,column=1)
 
fenetre.mainloop() | 
Partager