Advertisement
freakrho

Conectar wiimote

Mar 19th, 2013
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. import cwiid
  2.  
  3. c = input('Cuantos controles va a conectar? ')
  4. wm = []
  5. for i in range(c):
  6.     print 'Presione 1+2 en el Wiimote ' + str(i+1) + '...'
  7.     wm.append(cwiid.Wiimote())
  8.     wm[i].rpt_mode = cwiid.RPT_BTN | cwiid.RPT_IR | cwiid.RPT_ACC
  9.     wm[i].led = i+1
  10.  
  11. buttons = {8:'A', 4:'B', 2:'1', 1:'2', 16:'-', 4096:'+', 128:'Home', 2048:'Up', 1024:'Down', 256:'Left', 512:'Right'}
  12. bn = sorted(buttons.keys())
  13. bn.reverse()
  14.  
  15. def checkPressed(wm):
  16.     bp = wm.state['buttons']
  17.     p = []
  18.     for i in bn:
  19.         if i <= bp:
  20.             p.append(i)
  21.             bp -= i
  22.     pressed = []
  23.     for i in p:
  24.         pressed.append(buttons[i])
  25.     return pressed
  26.  
  27. while True:
  28.     #Buttons pressed
  29.     pressed = []
  30.     for i in range(c):
  31.         pressed.append(checkPressed(wm[i]))
  32.     print pressed
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement