Skip to content

Instantly share code, notes, and snippets.

@codejoust
Created December 15, 2011 15:59
Show Gist options
  • Save codejoust/1481611 to your computer and use it in GitHub Desktop.
Save codejoust/1481611 to your computer and use it in GitHub Desktop.
serial_py
import serial, cwiid, time, sys
print('Place wiimote in discoverable mode now')
wiimote = cwiid.Wiimote()
if not wiimote:
print('cannot find wiimote')
sys.exit()
board = serial.Serial('/dev/ttyUSB0', 9600);
print('connected')
wiimote.rpt_mode = cwiid.RPT_ACC
#range = 0 @ 120 && 90-120, 120 == 0, 120-140
#range = 0 @ 95 && 0 - 95, 95 - 180
while(1):
in_axis = wiimote.state['acc'][cwiid.Y]
zero = 115
print('going down %d' % in_axis)
if in_axis > zero - 6 and in_axis < zero + 6:
board.write('b95')
wiimote.led = 1
elif in_axis <= zero + 6:
board.write('b%d' % (in_axis - 40))
print('setting low - %d' % (in_axis - 40))
wiimote.led = 2
elif in_axis >= zero - 6:
board.write('b%d' % int(float(in_axis - 33)*1.3))
print('setting high - %d' % int(float(in_axis - 33)*1.3))
wiimote.led = 3
else:
wiimote.led = 4
time.sleep(0.4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment