fl { Wii nunchuk driver for PropForth Wii nunchuk Propeller clk P28 0x1c dat P29 0x1d Diagram below is showing the pinout looking into the connector (which plugs into the Wii Remote) _______ | 1 2 3 | | | | 6 5 4 | |_-----_| Peopeller 1 - SDA --------- P29 2 - 3 - VCC --------- 3.3V 4 - SCL --------- P28 5 - 6 - GND --------- GND Cutted connecter. 2012/8/8 VCC(Red) --------- 3.3V GND (White) --------- GND SDA(Green) --------- P29 SCL(Yellow) --------- P28 PropForth5.5 2013/05/21 16:38:46 PropForth4.6's WORDs are used to rename, because PropForth5.2/5.5 can't get datas from Wii-nunchaku. } : _PF4.6eeread _sdai 0 8 0 do 1 lshift _sclh _sda? _scll if 1 or then loop swap if _sdah else _sdal then _sdao _sclh _scll _sdal ; : _PF4.6eewrite h80 h8 0 do 2dup and if _sdah else _sdal then _sclh _scll 1 rshift loop 2drop _sdai _sclh _sda? _scll _sdal _sdao ; variable sx variable sy wvariable ax wvariable ay variable az wvariable cb wvariable z d127 wconstant cal_joy_x d135 wconstant cal_joy_y d525 wconstant cal_z d40000000 constant 500msec \ ( c1 -- ) write 1-byte : _slave_w _PF4.6eewrite if 8007 ERR then ; \ ( n1 n2 -- ) I2C Start n1:register-address n2:slave-address : _slave_s _eestart _slave_w \ slave address _slave_w \ register adress ; \ ( n1 -- ) only Data Read n1:slave-address : _slave_sr _eestart 1+ _slave_w \ slave address + rd[1] ; \ (n1 n2 n3 -- ) n1:i2cdata n2:register adress n3:slave address : nunchuck_location _slave_s _slave_w _eestop ; : init_nunchuck h55 hF0 hA4 nunchuck_location ; : readNunchaku 0 hFB hA4 nunchuck_location _eestart hA4 _slave_w 0 _slave_w _eestop _eestart hA4 _slave_sr 5 0 do 0 _PF4.6eeread loop -1 _PF4.6eeread _eestop ; : get_value dup 1 and z W! \ z-button dup 2 and cb W! \ c-button 2 rshift dup 3 and ax W! 2 rshift dup 3 and ay W! 2 rshift 3 and az L! 2 lshift az L@ + cal_z - az L! 2 lshift ay W+! 2 lshift ax W+! cal_joy_y - sy L! cal_joy_x - sx L! ; : test_Nunchaku init_nunchuck cnt COG@ 500msec + begin readNunchaku get_value ." SX:" sx L@ . ." SY:" sy L@ . ." AX:" ax W@ . ." AY:" ay W@ . ." AZ:" az L@ . ." c:" cb W@ . ." z:" z W@ . cr 500msec waitcnt fkey? swap drop until drop ; { test_Nunchaku SX:-1 SY:0 AX:323 AY:523 AZ:43 c:2 z:1 SX:-1 SY:0 AX:323 AY:523 AZ:45 c:2 z:1 SX:-1 SY:0 AX:313 AY:491 AZ:15 c:2 z:1 SX:-1 SY:0 AX:462 AY:512 AZ:146 c:2 z:1 SX:-9 SY:4 AX:562 AY:462 AZ:176 c:2 z:1 SX:-93 SY:-3 AX:562 AY:452 AZ:184 c:2 z:1 SX:93 SY:-15 AX:551 AY:449 AZ:186 c:2 z:1 SX:61 SY:-10 AX:547 AY:449 AZ:185 c:2 z:1 SX:-1 SY:94 AX:556 AY:451 AZ:186 c:2 z:1 SX:2 SY:-2 AX:556 AY:451 AZ:187 c:2 z:1 SX:27 SY:-94 AX:553 AY:445 AZ:187 c:2 z:1 SX:0 SY:-2 AX:494 AY:435 AZ:180 c:2 z:1 SX:0 SY:-2 AX:352 AY:428 AZ:66 c:2 z:1 SX:0 SY:-2 AX:384 AY:443 AZ:124 c:2 z:1 SX:0 SY:-2 AX:549 AY:464 AZ:191 c:2 z:1 SX:0 SY:-2 AX:673 AY:461 AZ:118 c:2 z:1 SX:0 SY:-2 AX:551 AY:556 AZ:199 c:2 z:1 SX:0 SY:-2 AX:526 AY:610 AZ:185 c:2 z:1 SX:0 SY:-2 AX:532 AY:443 AZ:189 c:2 z:1 SX:0 SY:-2 AX:502 AY:377 AZ:161 c:2 z:1 SX:0 SY:-2 AX:499 AY:309 AZ:-16 c:2 z:1 SX:0 SY:-2 AX:501 AY:313 AZ:-34 c:2 z:1 SX:0 SY:-2 AX:508 AY:342 AZ:112 c:2 z:1 SX:0 SY:-2 AX:499 AY:353 AZ:-154 c:2 z:1 SX:0 SY:-2 AX:524 AY:358 AZ:87 c:2 z:1 SX:0 SY:0 AX:540 AY:366 AZ:108 c:2 z:1 SX:0 SY:0 AX:512 AY:354 AZ:132 c:2 z:0 SX:0 SY:0 AX:518 AY:357 AZ:126 c:2 z:0 SX:0 SY:0 AX:516 AY:357 AZ:129 c:2 z:0 SX:0 SY:0 AX:516 AY:364 AZ:133 c:2 z:1 SX:0 SY:0 AX:517 AY:358 AZ:131 c:0 z:1 SX:0 SY:0 AX:516 AY:360 AZ:129 c:0 z:1 SX:0 SY:0 AX:514 AY:359 AZ:127 c:0 z:1 SX:0 SY:0 AX:508 AY:351 AZ:129 c:0 z:1 SX:0 SY:0 AX:414 AY:490 AZ:170 c:2 z:1 Prop0 Cog6 ok }