fl hex { 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 PropForth 4.6 15/08/2011 23:04:02 } : _eeread _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 ; : _eewrite 80 8 0 do 2dup and if _sdah else _sdal then _sclh _scll 1 rshift loop 2drop _sdai _sclh _sda? _scll _sdal _sdao ; wvariable sx wvariable sy wvariable ax wvariable ay wvariable az wvariable cb wvariable z \ ( c1 -- ) write 1-byte : _slave_w _eewrite 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 55 F0 A4 nunchuck_location ; : readNunchuck 0 FB A4 nunchuck_location _eestart A4 _slave_w 0 _slave_w _eestop _eestart A4 _slave_sr 5 0 do 0 _eeread loop -1 _eeread _eestop ; : test init_nunchuck 200 0 do readNunchuck dup 1 and z W! \ c-button dup 2 and cb W! \ z-button 2 rshift dup 3 and az W! 2 rshift dup 3 and ay W! 2 rshift 3 and ax W! 2 lshift az W+! 2 lshift ay W+! 2 lshift ax W+! sy W! sx W! ." SX:" sx W@ . ." SY:" sy W@ . ." AX:" ax W@ . ." AY:" ay W@ . ." AZ:" az W@ . ." c:" cb W@ . ." z:" z W@ . cr 100 delms loop ; : get_value dup 1 and z W! \ c-button dup 2 and cb W! \ z-button 2 rshift dup 3 and az W! 2 rshift dup 3 and ay W! 2 rshift 3 and ax W! 2 lshift az W+! 2 lshift ay W+! 2 lshift ax W+! sy W! sx W! ; : Wii_demo lcd_init 10 4 lcd_setup \ 16characters 4line c" SX: SY:" lcd_str 1 2 lcd_pos c" AX: C:" lcd_str 1 3 lcd_pos c" AY: Z:" lcd_str 1 4 lcd_pos c" AZ:" lcd_str init_nunchuck begin readNunchuck get_value 4 1 lcd_pos sx W@ dup lcd_dec 64 < if 6 1 lcd_pos 20 lcd_char then B 1 lcd_pos sy W@ dup lcd_dec 64 < if D 1 lcd_pos 20 lcd_char then 4 2 lcd_pos ax W@ lcd_dec A 2 lcd_pos cb W@ 2 = if 30 else 31 then lcd_char 4 3 lcd_pos ay W@ lcd_dec A 3 lcd_pos z W@ 1 = if 30 else 31 then lcd_char 4 4 lcd_pos az W@ lcd_dec 100 delms fkey? swap drop until ; decimal