Created
December 15, 2011 15:59
-
-
Save codejoust/1481611 to your computer and use it in GitHub Desktop.
serial_py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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