Skip to content

Instantly share code, notes, and snippets.

@kennethklee
Created April 5, 2016 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kennethklee/181750488c71cc96ff5952300fe76999 to your computer and use it in GitHub Desktop.
Save kennethklee/181750488c71cc96ff5952300fe76999 to your computer and use it in GitHub Desktop.
Wii board weight code
#!/usr/bin/env python
import wiiboard
import pygame
import time
import sys
def main():
board = wiiboard.Wiiboard()
pygame.init()
address = board.discover()
board.connect(address) #The wii board must be in sync mode at this time
time.sleep(0.1)
board.setLight(True)
done = False
mass = 0.0
button = 0
while (not done):
time.sleep(0.05)
for event in pygame.event.get():
if event.type == wiiboard.WIIBOARD_MASS:
mass = event.mass.totalWeight
elif event.type == wiiboard.WIIBOARD_BUTTON_PRESS:
button = 1
elif event.type == wiiboard.WIIBOARD_BUTTON_RELEASE:
button = 0
#Other event types:
#wiiboard.WIIBOARD_CONNECTED
#wiiboard.WIIBOARD_DISCONNECTED
# print("\rMass: %.2f Button: %d" % (mass, button))
sys.stdout.write('Mass: {0:.2f} kg or {1:.2f} lbs | Button: {2} {3:.2f} {4:.2f} {5:.2f} {6:.2f} \r'.format(mass, mass * 2.2, button, event.mass.topLeft, event.mass.topRight, event.mass.bottomLeft, event.mass.bottomRight))
sys.stdout.flush()
board.disconnect()
pygame.quit()
#Run the script if executed
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment