- !/usr/bin/python
- -*- coding: utf-8 -*-
from Tkinter import *
from math import sin,pi
import cwiid
import time
class Application(object):
def __init__(self):
self.fen = Tk()
self.fen.title("Wiimote : accelerometre ")
self.fen.geometry("300x300")
Label(self.fen,text='valeur du temps').pack(side=RIGHT)
self.entree2=Entry(self.fen,width=14)
self.entree2.pack(side=RIGHT)
b2=Button(self.fen,text='Nouvelle courbe : appuyez sur 1+2 ',command=self.traceCourbe)
b2.pack(side=RIGHT,padx=3,pady=3)
b3=Button(self.fen,text='Detection wiimote : appuez sur 1+ 2',command=self.reconnaissance).pack()
self.fen.mainloop()
def reconnaissance(self):
led = 0
rpt_mode = 0
rumble = 0
mesg = False
if len(sys.argv) > 1:
wiimote = cwiid.Wiimote(sys.argv[1])
else:
wiimote = cwiid.Wiimote()
rpt_mode = cwiid.RPT_ACC
wiimote.rpt_mode = rpt_mode
lab=Label(self.fen,text='Wiimote detecté').pack()
def traceCourbe(self):
self.can=Canvas(self.fen,width=500,height=500)
self.can.grid(row=1,column=1,columnspan=1,pady=1,p
adx=1)
x_acc = [0]
y_acc = [0]
z_acc = [0]
t = [0]
curve=[]
led = 0
rpt_mode = 0
rumble = 0
mesg = False
if len(sys.argv) > 1:
wiimote = cwiid.Wiimote(sys.argv[1])
else:
wiimote = cwiid.Wiimote()
rpt_mode = cwiid.RPT_ACC
wiimote.rpt_mode = rpt_mode
zorg = None
self.v1=self.entree2.get()
zorg=float(self.v1)
tic = time.time()
while not t[-1] > zorg:
t.append(time.time() - tic)
x_acc.append(wiimote.state["acc"][cwiid.X])
y_acc.append(wiimote.state["acc"][cwiid.Y])
z_acc.append(wiimote.state["acc"][cwiid.Z])
#~ print "t =", t[-1], "; ax =", x_acc[-1], \
#~ "; ay =", y_acc[-1], \
#~ "; az =", y_acc[-1]
"trace d'une grpoahique "
curve=[]
curve1=[]
curve2=[]
curve.append((t,x_acc))
self.can.create_line(curve,width=1,fill='yellow',s
mooth=1)
x=[0]
y=[0]
x1=[0]
y1=[0]
x1=0
while x1<100:
y1=x1*x1
x1=x1+1
curve2.append((x1,y1))
self.can.create_line(curve2,width=1,fill='red')
if __name__== '__main__':
fen = Application()