Step 47: Full code (potentiometer steering)
It is attached as a text file to copy and paste into a new arduino sketch, compile and save.
Open this sketch. We need to adjust the value of 338 to fine tune the balance point as before:
How to do this:
As when we tweaked the IMU tester: alter the value of 338 (if you need to) in this line of code in for the value you wrote down for accsum when running IMU tester and holding your board level: x_accdeg = (float)((accsum - 338) * 0.862);
Recompile the balance code with this new value in and you are now ready to try it out.
Updated February 25th 2012.
It works with Arduino V22. They have now released a newer version (V1.0) with a new softserial library with slightly different softserial commands so it might not work with very latest version of Arduino.
If you open up a proper Nintenso Wii Nunchuck (with special 3 lobed "Nintendo" screwdriver you have to buy on ebay) you will see that under thumb joystick is catually just 2 x 16 k potentiometers, one for side to side movement (steering) and another for forward/back (fine tune balance point). If you have a Chinese copy the potentiometer is about 3.5K, you can tell difference by the price as they look identical. You can actually solder wires onto the 3 pins of each potentiometer if you are careful and also 2 wires to one of the end buttons to use as a the deadman switch. Good thing about these potentiometers is that they self-centre at about 5-7 K Ohms.
Use multicore cable and run it back to your arduino board and you have a neat hand controller.
You may possibly have to alter values slightly in the code for the readings on analog ports on a scale from 0 - 1023