Created
January 26, 2014 20:30
-
-
Save mdobson/8639105 to your computer and use it in GitHub Desktop.
Wiichuck Arduino Integration
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
/* | |
* WiiChuckDemo -- | |
* | |
* 2008 Tod E. Kurt, http://thingm.com/ | |
* | |
*/ | |
#include <Wire.h> | |
#include "nunchuck_funcs.h" | |
int loop_cnt=0; | |
byte accx,accy,zbut,cbut; | |
int leftPin = 8; | |
int rightPin = 13; | |
int firePin = 12; | |
void setup() | |
{ | |
Serial.begin(19200); | |
pinMode(leftPin, OUTPUT); | |
pinMode(rightPin, OUTPUT); | |
pinMode(firePin, OUTPUT); | |
nunchuck_setpowerpins(); | |
nunchuck_init(); // send the initilization handshake | |
Serial.print("WiiChuckDemo ready\n"); | |
} | |
void loop() | |
{ | |
if( loop_cnt > 100 ) { // every 100 msecs get new data | |
loop_cnt = 0; | |
nunchuck_get_data(); | |
accx = nunchuck_joyx(); // ranges from approx 70 - 182 | |
accy = nunchuck_joyy(); // ranges from approx 65 - 173 | |
zbut = nunchuck_zbutton(); | |
cbut = nunchuck_cbutton(); | |
if(accx == 225) | |
{ | |
digitalWrite(rightPin, HIGH); | |
} | |
else if(accx == 32) | |
{ | |
digitalWrite(leftPin, HIGH); | |
} | |
else | |
{ | |
digitalWrite(leftPin, LOW); | |
digitalWrite(rightPin, LOW); | |
} | |
if(zbut == 1) | |
{ | |
digitalWrite(firePin, HIGH); | |
} | |
else | |
{ | |
digitalWrite(firePin, LOW); | |
} | |
Serial.print("joyx: "); Serial.print((byte)accx,DEC); | |
Serial.print("\tjoyy: "); Serial.print((byte)accy,DEC); | |
Serial.print("\tzbut: "); Serial.print((byte)zbut,DEC); | |
Serial.print("\tcbut: "); Serial.println((byte)cbut,DEC); | |
} | |
loop_cnt++; | |
delay(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment