<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Nunchuk Programming</title>
<description> Perhaps I missed this, but I&amp;#039;ve been looking through libogc for a while and I can&amp;#039;t find to way to program in input from the Nunchuk&amp;#039;s analog stick (or motion control for the nunchuk, but I don&amp;#039;t care about that). I would appreciate any help anyone could give me.

-Thanks,
Arikado</description><link>http://forum.wiibrew.org/read.php?11,1334,1334#msg-1334</link><lastBuildDate>Wed, 16 Sep 2026 14:52:25 +0200</lastBuildDate>
<generator>Phorum 5.2.23</generator>
<item>
<guid>http://forum.wiibrew.org/read.php?11,1334,26967#msg-26967</guid>
<title>Re: Nunchuk Programming</title><link>http://forum.wiibrew.org/read.php?11,1334,26967#msg-26967</link><description><![CDATA[ That makes sense. When I got home last night I used ArielX&#039;s example code to display what the min and max values were: for my unit it was roughly -100 to 100. I didn&#039;t even notice the min and max values in the struct. I came up with a rough formula that was fairly close.<br /><br />In my testing, I didn&#039;t really like the response of the controller when mapping joystick position to screen coordinates. I may try using a proportional velocity instead and see how that feels.<br /><br />Thanks for the help.]]></description>
<dc:creator>scarter11</dc:creator>
<category>Coding</category><pubDate>Wed, 29 Jul 2009 13:52:12 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,1334,26961#msg-26961</guid>
<title>Re: Nunchuk Programming</title><link>http://forum.wiibrew.org/read.php?11,1334,26961#msg-26961</link><description><![CDATA[ <blockquote class="bbcode"><div><small>Quote<br /></small><strong>scarter11</strong><br />Anyone have any ideas on a way to convert data.nunchuk.js.pos.x to a screen x value?<br /><br />I&#039;m assuming the range of values for data.js.pos.x is different than the screen x coordinate range. I haven&#039;t had a chance to confirm that.</div></blockquote>
Assuming that js is data.nunchuk.js:<br />screen_x=(js.pos.x-js.min.x)*screen_w/(js.max.x-js.min.x)<br />and same for y:<br />screen_y=(js.pos.y-js.min.y)*screen_h/(js.max.y-js.min.y)<br />screen_w and screen_h are usually 640 and 480.<br /><br />I&#039;m gonna explain myself a bit: range of values that nunchuck gives are between js.max and js.min. So their subtraction js.max-js.min tells the "width"/"height" of nunchuck movement.<br />So when we divide screen width with nunchuk "width" we get the number that translates nunchuk coordinate to screen coordinate by multiplying. Then we just have to multiply js.pos.x with that number. However we have to subtract js.min.x from js.pos.x to map the position to start from 0 to nunchuk "width"<br /><br />I don&#039;t know if you can understand very well what I&#039;m writing because I&#039;m not native english speaker :)]]></description>
<dc:creator>Dande</dc:creator>
<category>Coding</category><pubDate>Wed, 29 Jul 2009 11:07:43 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,1334,26816#msg-26816</guid>
<title>Re: Nunchuk Programming</title><link>http://forum.wiibrew.org/read.php?11,1334,26816#msg-26816</link><description><![CDATA[ My first wii game is another clone of the old Activision game Kaboom. I want to use the x axis of the nunchuk for movement. I tried using the wiimote&#039;s ir, but it is just not responsive enough. Ideally, if the nunchuk joystick is moved to the far left, the barrel would move to the far left (x coordinate 0).<br /><br />Anyone have any ideas on a way to convert data.nunchuk.js.pos.x to a screen x value?<br /><br />I&#039;m assuming the range of values for data.js.pos.x is different than the screen x coordinate range. I haven&#039;t had a chance to confirm that.]]></description>
<dc:creator>scarter11</dc:creator>
<category>Coding</category><pubDate>Tue, 28 Jul 2009 13:55:00 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,1334,1679#msg-1679</guid>
<title>Re: Nunchuk Programming</title><link>http://forum.wiibrew.org/read.php?11,1334,1679#msg-1679</link><description><![CDATA[ Did not see it sorry, thanks, I thought it was that, just wasn&#039;t sure.]]></description>
<dc:creator>WiiPhlex</dc:creator>
<category>Coding</category><pubDate>Sat, 06 Sep 2008 01:48:32 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,1334,1663#msg-1663</guid>
<title>Re: Nunchuk Programming</title><link>http://forum.wiibrew.org/read.php?11,1334,1663#msg-1663</link><description><![CDATA[ I used the rumbling with a timer that has it rumble for about half a second. It will be in the next release of Wii Shooting Gallery.<br /><br />EDIT: And, erm, by the way WiiPhlex you could have just posted this in the Wiimote Rumbling topic.]]></description>
<dc:creator>Arikado</dc:creator>
<category>Coding</category><pubDate>Fri, 05 Sep 2008 21:29:50 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,1334,1658#msg-1658</guid>
<title>Re: Nunchuk Programming</title><link>http://forum.wiibrew.org/read.php?11,1334,1658#msg-1658</link><description><![CDATA[ There&#039;s a small motor inside the Wii remote that can make it vibrate. Ever used a Playstation 1 or 2 controller and felt it shake a bit when you got hit in the game? The Wii remote can do that too.]]></description>
<dc:creator>Rorschach</dc:creator>
<category>Coding</category><pubDate>Fri, 05 Sep 2008 19:16:25 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,1334,1653#msg-1653</guid>
<title>Re: Nunchuk Programming</title><link>http://forum.wiibrew.org/read.php?11,1334,1653#msg-1653</link><description><![CDATA[ I know this isn&#039;t entirely on topic, but didn&#039;t deserve a topic of it&#039;s own in my opinion. Can someone tell me what rumble is? I don&#039;t have a wii so I don&#039;t know these things.]]></description>
<dc:creator>WiiPhlex</dc:creator>
<category>Coding</category><pubDate>Fri, 05 Sep 2008 15:22:33 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,1334,1572#msg-1572</guid>
<title>Re: Nunchuk Programming</title><link>http://forum.wiibrew.org/read.php?11,1334,1572#msg-1572</link><description><![CDATA[ Fascinating, hopefully I&#039;ll have some time to play around with that soon.]]></description>
<dc:creator>Arikado</dc:creator>
<category>Coding</category><pubDate>Wed, 03 Sep 2008 14:02:48 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,1334,1555#msg-1555</guid>
<title>Re: Nunchuk Programming</title><link>http://forum.wiibrew.org/read.php?11,1334,1555#msg-1555</link><description><![CDATA[ Shake detection is easy, just check if the force is anything other than the (normal of the) gravitational acceleration.]]></description>
<dc:creator>henke37</dc:creator>
<category>Coding</category><pubDate>Wed, 03 Sep 2008 07:05:03 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,1334,1552#msg-1552</guid>
<title>Re: Nunchuk Programming</title><link>http://forum.wiibrew.org/read.php?11,1334,1552#msg-1552</link><description><![CDATA[ Either way is good. I may prefer ang + mag simply because 0.9f is easier to read / more obvious than a magic number for X and Y. X and Y are simple though, so go with whatever you&#039;re comfortable with.<br /><br />As for the shake, dunno, I&#039;ve never used the motion sensors of the Wiimore or Nunchuk. You&#039;re on your own for this one :P, just look at the headers and read up on the wiiuse documentation.]]></description>
<dc:creator>AerialX</dc:creator>
<category>Coding</category><pubDate>Wed, 03 Sep 2008 03:00:25 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,1334,1524#msg-1524</guid>
<title>Re: Nunchuk Programming</title><link>http://forum.wiibrew.org/read.php?11,1334,1524#msg-1524</link><description><![CDATA[ It is, but I originally learned angles and orientation so I&#039;m used to that. Anyways, I still want to figure out how to check for a shake of nunchuck.]]></description>
<dc:creator>Arikado</dc:creator>
<category>Coding</category><pubDate>Tue, 02 Sep 2008 14:42:55 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,1334,1516#msg-1516</guid>
<title>Re: Nunchuk Programming</title><link>http://forum.wiibrew.org/read.php?11,1334,1516#msg-1516</link><description><![CDATA[ I still prefer good old X and Y. It&#039;s so much faster to compare those.]]></description>
<dc:creator>henke37</dc:creator>
<category>Coding</category><pubDate>Tue, 02 Sep 2008 07:53:14 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,1334,1496#msg-1496</guid>
<title>Re: Nunchuk Programming</title><link>http://forum.wiibrew.org/read.php?11,1334,1496#msg-1496</link><description><![CDATA[ Solved! Did a little reading... Found some good source... Did a little modifying... Enjoy! :)<br /><br /><pre class="bbcode">
//Nunchuck Up
if((exp.nunchuk.js.ang&gt;=315 || exp.nunchuk.js.ang&lt;=45) && exp.nunchuk.js.mag&gt;=0.9)

//Nunchuck Right
if((exp.nunchuk.js.ang&gt;=90-45 && exp.nunchuk.js.ang&lt;=90+45) && exp.nunchuk.js.mag&gt;=0.9)

//Nunchuck Down
if((exp.nunchuk.js.ang&gt;=180-45 && exp.nunchuk.js.ang&lt;=180+45) && exp.nunchuk.js.mag&gt;=0.9)

//Nunchuck Left
if((exp.nunchuk.js.ang&gt;=270-45 && exp.nunchuk.js.ang&lt;=270+45) && exp.nunchuk.js.mag&gt;=0.9)
</pre>]]></description>
<dc:creator>Arikado</dc:creator>
<category>Coding</category><pubDate>Mon, 01 Sep 2008 23:08:19 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,1334,1417#msg-1417</guid>
<title>Re: Nunchuk Programming</title><link>http://forum.wiibrew.org/read.php?11,1334,1417#msg-1417</link><description><![CDATA[ Good thing I haven&#039;t gotten around to it yet :). I&#039;ll post the working if&#039;s I come up with when I&#039;m done.]]></description>
<dc:creator>Arikado</dc:creator>
<category>Coding</category><pubDate>Sat, 30 Aug 2008 22:47:32 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,1334,1408#msg-1408</guid>
<title>Re: Nunchuk Programming</title><link>http://forum.wiibrew.org/read.php?11,1334,1408#msg-1408</link><description><![CDATA[ Well yeah, but one thing I forgot to mention/use... The joystick_t has a "center" field. Change my printf line to:<br /><br /><pre class="bbcode">
			vec2b_t center = data.nunchuk.js.center;
			printf("Nunchuk X: %d     \n Nunchuk Y: %d     \n", data.nunchuk.js.pos.x - center.x, data.nunchuk.js.pos.y - center.y);</pre><br />Then play with those x and y values. I forgot about joystick center/neutral calibration &gt;.&gt;]]></description>
<dc:creator>AerialX</dc:creator>
<category>Coding</category><pubDate>Sat, 30 Aug 2008 18:28:09 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,1334,1405#msg-1405</guid>
<title>Re: Nunchuk Programming</title><link>http://forum.wiibrew.org/read.php?11,1334,1405#msg-1405</link><description><![CDATA[ Beautiful, thanks AerialX. And then for if&#039;s I can just play around with the x and y values, correct?]]></description>
<dc:creator>Arikado</dc:creator>
<category>Coding</category><pubDate>Sat, 30 Aug 2008 16:36:23 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,1334,1394#msg-1394</guid>
<title>Re: Nunchuk Programming</title><link>http://forum.wiibrew.org/read.php?11,1334,1394#msg-1394</link><description><![CDATA[ Gah, don&#039;t know why I did this &gt;.&gt;<br /><br />Here&#039;s your example, kk? Notice how ugly the Nunchuk&#039;s X and Y values are, I&#039;d personally prefer to use mag and ang :P<br /><br />Instructions:<br />Copy the Wii template from wii-examples...<br />Replace template.c with:<br /><pre class="bbcode">#include <stdio.h>

#include <stdlib.h>

#include <gccore.h>

#include <wiiuse/wpad.h>



static void *xfb = NULL;

static GXRModeObj *rmode = NULL;



//---------------------------------------------------------------------------------

int main(int argc, char **argv) {

//---------------------------------------------------------------------------------



	// Initialise the video system

	VIDEO_Init();

	

	// This function initialises the attached controllers

	WPAD_Init();

	

	// Obtain the preferred video mode from the system

	// This will correspond to the settings in the Wii menu

	rmode = VIDEO_GetPreferredMode(NULL);



	// Allocate memory for the display in the uncached region

	xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));

	

	// Initialise the console, required for printf

	console_init(xfb,20,20,rmode-&gt;fbWidth,rmode-&gt;xfbHeight,rmode-&gt;fbWidth*VI_DISPLAY_PIX_SZ);

	

	// Set up the video registers with the chosen mode

	VIDEO_Configure(rmode);

	

	// Tell the video hardware where our display memory is

	VIDEO_SetNextFramebuffer(xfb);

	

	// Make the display visible

	VIDEO_SetBlack(FALSE);



	// Flush the video register changes to the hardware

	VIDEO_Flush();



	// Wait for Video setup to complete

	VIDEO_WaitVSync();

	if(rmode-&gt;viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();



	while (1) {

		// The console understands VT terminal escape codes

		// This positions the cursor on row 2, column 0

		// we can use variables for this with format codes too

		// e.g. printf ("\x1b[%d;%dH", row, column );

		printf("\x1b[2;0H");

	



		printf("Hello World!\n");



		// Call WPAD_ScanPads each loop, this reads the latest controller states

		WPAD_ScanPads();



		// WPAD_ButtonsDown tells us which buttons were pressed in this loop

		// this is a "one shot" state which will not fire again until the button has been released

		u32 pressed = WPAD_ButtonsDown(0);



		// We return to the launcher application via exit

		if ( pressed & WPAD_BUTTON_HOME ) exit(0);



		struct expansion_t data;

		WPAD_Expansion(WPAD_CHAN_0, &data); // Get expansion info from the first wiimote



		if (data.type == WPAD_EXP_NUNCHUK) { // Ensure there&#039;s a nunchuk

			printf("Nunchuk X: %d\n Nunchuk Y: %d\n", data.nunchuk.js.pos.x, data.nunchuk.js.pos.y);

		}



		// Wait for the next frame

		VIDEO_WaitVSync();

	}



	return 0;

}</pre>
Compile and run via wiiload/TP, plug in a nunchuk (before or after running it) and move the joystick around.]]></description>
<dc:creator>AerialX</dc:creator>
<category>Coding</category><pubDate>Sat, 30 Aug 2008 04:52:10 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,1334,1391#msg-1391</guid>
<title>Re: Nunchuk Programming</title><link>http://forum.wiibrew.org/read.php?11,1334,1391#msg-1391</link><description><![CDATA[ I doubt there is one that uses libwiisprite, but why would it matter if it was libwiisprite anyway? It would use a graphics library that updated the x and y pos anyways so it would be pretty much the same.]]></description>
<dc:creator>WiiPhlex</dc:creator>
<category>Coding</category><pubDate>Sat, 30 Aug 2008 04:13:57 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,1334,1381#msg-1381</guid>
<title>Re: Nunchuk Programming</title><link>http://forum.wiibrew.org/read.php?11,1334,1381#msg-1381</link><description><![CDATA[ Is there an example of source I can look at for this (preferably one that uses libwiisprite)?]]></description>
<dc:creator>Arikado</dc:creator>
<category>Coding</category><pubDate>Fri, 29 Aug 2008 22:21:56 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,1334,1377#msg-1377</guid>
<title>Re: Nunchuk Programming</title><link>http://forum.wiibrew.org/read.php?11,1334,1377#msg-1377</link><description><![CDATA[ <blockquote class="bbcode"><div><small>Quote<br /></small><strong>henke37</strong><br />Personally I think that the ang and mag properties are bloat. It&#039;s not that fircking hard to do it yourself, but only when needed.<br />I just want access to normal scaled X and Y values.</div></blockquote>
True enough, so just use the pos field instead. Again, there&#039;s no instant way to check for a "down" press or not, but just pick a reasonable threshold for the X and Y values.]]></description>
<dc:creator>AerialX</dc:creator>
<category>Coding</category><pubDate>Fri, 29 Aug 2008 20:50:51 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,1334,1376#msg-1376</guid>
<title>Re: Nunchuk Programming</title><link>http://forum.wiibrew.org/read.php?11,1334,1376#msg-1376</link><description><![CDATA[ Personally I think that the ang and mag properties are bloat. It&#039;s not that fircking hard to do it yourself, but only when needed.<br />I just want access to normal scaled X and Y values.]]></description>
<dc:creator>henke37</dc:creator>
<category>Coding</category><pubDate>Fri, 29 Aug 2008 19:41:10 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,1334,1373#msg-1373</guid>
<title>Re: Nunchuk Programming</title><link>http://forum.wiibrew.org/read.php?11,1334,1373#msg-1373</link><description><![CDATA[ Unfortunately you can&#039;t do that. If it did exist, what would count as a down event? It&#039;s not a button, you&#039;d have to specify a magnitude (maybe half/0.5) that counts as a press (and find out what angle counts for what directions). In any case, libogc isn&#039;t all that high-level, and won&#039;t make that call for you.<br /><br />You can make a function for it yourself though. Use the mag and ang fields of joystick to see where the analog stick is pointing and how much it&#039;s being pressed. It&#039;s more complicated than just checking directional events because it&#039;s an analog stick and not a button, but you can write your own code that will check it like a button.]]></description>
<dc:creator>AerialX</dc:creator>
<category>Coding</category><pubDate>Fri, 29 Aug 2008 17:48:21 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,1334,1362#msg-1362</guid>
<title>Re: Nunchuk Programming</title><link>http://forum.wiibrew.org/read.php?11,1334,1362#msg-1362</link><description><![CDATA[ I just want a line along these lines:<br /><br />if(WPAD_NUNCHUK_DOWN)<br />do someting<br /><br />and also up, left, and right.]]></description>
<dc:creator>Arikado</dc:creator>
<category>Coding</category><pubDate>Fri, 29 Aug 2008 15:15:10 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,1334,1346#msg-1346</guid>
<title>Re: Nunchuk Programming</title><link>http://forum.wiibrew.org/read.php?11,1334,1346#msg-1346</link><description><![CDATA[ Just improvising here, but something along these lines:<br /><br /><pre class="bbcode">
// Assuming WPAD is all set up...
struct expansion_t data;
WPAD_Expansion(WPAD_CHAN_0, &data); // Get expansion info from the first wiimote

if (data.type == WPAD_EXP_NUNCHUK) { // Ensure there&#039;s a nunchuk
do something with data.nunchuk.joystick
}</pre><br />data.nunchuk.joystick is of type joystick_t defined in wiiuse/wiiuse.h:<br /><pre class="bbcode">
typedef struct joystick_t {
        struct vec2b_t max;                             /**&lt; maximum joystick values    */
        struct vec2b_t min;                             /**&lt; minimum joystick values    */
        struct vec2b_t center;                  /**&lt; center joystick values             */
        struct vec2b_t pos;                             /**&lt; raw position values        */

        float ang;                                              /**&lt; angle the joystick is being held           */
        float mag;                                              /**&lt; magnitude of the joystick (range 0-1)      */
} joystick_t;</pre>]]></description>
<dc:creator>AerialX</dc:creator>
<category>Coding</category><pubDate>Fri, 29 Aug 2008 01:47:05 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,1334,1338#msg-1338</guid>
<title>Re: Nunchuk Programming</title><link>http://forum.wiibrew.org/read.php?11,1334,1338#msg-1338</link><description><![CDATA[ This was all I could find that mught be of use, but unfortunately I lack a proper example to understand its use:<br /><br /><pre class="bbcode">
#define WPAD_THRESH_DEFAULT_JOYSTICK			2

void WPAD_Orientation(int chan, struct orient_t *orient);
void WPAD_GForce(int chan, struct gforce_t *gforce);
void WPAD_Accel(int chan, struct vec3b_t *accel);
void WPAD_Expansion(int chan, struct expansion_t *exp);</pre><br />Would someone please explain this for me?<br /><br />EDIT: Sorry if I&#039;m missing something "really obvious", but before Wii I only programmed on the pc with the allegro angine and I never worked with the joystick.]]></description>
<dc:creator>Arikado</dc:creator>
<category>Coding</category><pubDate>Thu, 28 Aug 2008 23:39:03 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,1334,1335#msg-1335</guid>
<title>Re: Nunchuk Programming</title><link>http://forum.wiibrew.org/read.php?11,1334,1335#msg-1335</link><description><![CDATA[ Take a look through wiiuse/wpad.h (inside the libogc include directory). <a href="http://www.wiiuse.net/?nav=api" rel="nofollow">The wiiuse guide</a> should help you understand a bit how WPAD works behind the scenes, although you don&#039;t use wiiuse directly. WPAD is fairly self-explanatory anyway, just studying the header should help you find out how to read data from extension controllers (and how to check what extension is currently connected).]]></description>
<dc:creator>AerialX</dc:creator>
<category>Coding</category><pubDate>Thu, 28 Aug 2008 20:50:05 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,1334,1334#msg-1334</guid>
<title>Nunchuk Programming</title><link>http://forum.wiibrew.org/read.php?11,1334,1334#msg-1334</link><description><![CDATA[ Perhaps I missed this, but I&#039;ve been looking through libogc for a while and I can&#039;t find to way to program in input from the Nunchuk&#039;s analog stick (or motion control for the nunchuk, but I don&#039;t care about that). I would appreciate any help anyone could give me.<br /><br />-Thanks,<br />Arikado]]></description>
<dc:creator>Arikado</dc:creator>
<category>Coding</category><pubDate>Thu, 28 Aug 2008 20:13:19 +0200</pubDate></item>
</channel>
</rss>