Guest User

wii binary input with python

a guest
Jul 26th, 2012
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. keepishop@velma:~/wii$ cat wiibin.py
  2. import cwiid
  3. import time
  4. import array
  5.  
  6.  
  7. print 'Press 1+2 on your Wiimote now...'
  8. wm = cwiid.Wiimote()
  9.  
  10. time.sleep(1)
  11.  
  12. wm.rpt_mode = cwiid.RPT_BTN | cwiid.RPT_ACC
  13.  
  14. print 'Now press A or B'
  15.  
  16. binarray=array.array('c',['0','0','0','0','0','0','0','0'])
  17. binkey=0
  18.  
  19. while True:
  20. if wm.state['buttons'] & cwiid.BTN_A:
  21. wm.led = (wm.state['led'] + 1) % 8
  22. binarray[binkey]='1'
  23. binkey=(binkey+1) % 8
  24. if binkey == 0:
  25. print (chr(int(binarray.tostring(),2)))
  26. print (binarray.tostring())
  27. wm.rumble=1
  28. time.sleep(.2)
  29. wm.rumble=0
  30. while wm.state['buttons'] & cwiid.BTN_A:
  31. time.sleep(.01)
  32. if wm.state['buttons'] & cwiid.BTN_B:
  33. wm.led = (wm.state['led'] + 1) % 8
  34. binarray[binkey]='0'
  35. binkey=(binkey+1) % 8
  36. if binkey == 0:
  37. print (chr(int(binarray.tostring(),2)))
  38. print (binarray.tostring())
  39. wm.rumble=1
  40. time.sleep(.2)
  41. wm.rumble=0
  42. while wm.state['buttons'] & cwiid.BTN_B:
  43. time.sleep(.01)
Advertisement
Add Comment
Please, Sign In to add comment