This is an arduino library for talking to the Wii Classic Controller over i2c. The hardware is the same as the Wii Nunchuck.
/* WiiClassic Test Code
This code prints the current controller status to the serial port. Button pressed calls poll whether the button was pressed since the last update call. as a result, it will just briefly print the last button pressed once.
void loop() { delay(100); // 1ms is enough to not overload the wii Classic, 100ms seems to ease the serial terminal a little wiiClassy.update();
// /* // PRINT RAW BYTES FOR DEBUG // STATUS IS FIRST FOUR BYTES for (int i = 0; i < 4; i ++) { for (int j = 7; j >= 0; j--) { if ((wiiClassy.getRawStatus()[i] & (1 << j)) == 0) { Serial.print("0"); } else{ Serial.print("1"); } } Serial.println(); } // BUTTONS IS NEXT TWO BYTES for (int i = 0; i < 2; i ++) { for (int j = 7; j >= 0; j--) { if ((wiiClassy.getRawButtons()[i] & (1 << j)) == 0) { Serial.print("0"); } else{ Serial.print("1"); } } Serial.println(); } Serial.println("---"); */
Serial.print("Buttons:");
if (wiiClassy.leftShoulderPressed()) { Serial.print("LS."); } if (wiiClassy.rightShoulderPressed()) { Serial.print("RS."); } if (wiiClassy.lzPressed()) { Serial.print("lz."); } if (wiiClassy.rzPressed()) { Serial.print("rz."); } if (wiiClassy.leftDPressed()) { Serial.print("LD."); }
if (wiiClassy.rightDPressed()) { Serial.print("RD."); }
if (wiiClassy.upDPressed()) { Serial.print("UD."); } if (wiiClassy.downDPressed()) { Serial.print("DD."); }
if (wiiClassy.selectPressed()) { Serial.print("select."); }
if (wiiClassy.homePressed()) { Serial.print("home."); } if (wiiClassy.startPressed()) { Serial.print("start."); }
if (wiiClassy.xPressed()) { Serial.print("x."); }
if (wiiClassy.yPressed()) { Serial.print("y."); }
if (wiiClassy.aPressed()) { Serial.print("a."); }
if (wiiClassy.bPressed()) { Serial.print("b."); }
Serial.println(); Serial.print("right shoulder: "); Serial.println(wiiClassy.rightShouldPressure()); Serial.print(" left shoulder: ");
Serial.println(wiiClassy.leftShouldPressure()); Serial.print(" left stick x: ");
Serial.println(wiiClassy.leftStickX()); Serial.print(" left stick y: ");
Serial.println(wiiClassy.leftStickY()); Serial.print(" right stick x: ");
Serial.println(wiiClassy.rightStickX()); Serial.print(" right stick y: ");
/*
* Wii Classic -- Use a Wii Classic Controller
* by Tim Hirzel https://www.growdown.com
*
*
* This code owes thanks to the code by these authors:
* Tod E. Kurt, https://todbot.com/blog/
*
* The Wii Nunchuck reading code is taken from Windmeadow Labs
* https://www.windmeadow.com/node/42
*
* and the reference document on the wii linux site:
* https://www.wiili.org/index.php/Wiimote/Extension_Controllers/Classic_Controller
*/
#include <Wire.h>
#ifndef WiiClassic_h #define WiiClassic_h
class WiiClassic {
private:
byte cnt; uint8_t status[4];// array to store wiichuck output
byte averageCounter; //int accelArray[3][AVERAGE_N]; // X,Y,Z
We care about the privacy and personal data of our users.
To continue, please give us your consent:
Please confirm that you have read the privacy policy
Thank you for subscribing!
Curious to learn more?
Are you also a teacher, student, or professional that loves using Arduino in your day-to-day activities?
Then keep up-to-date with either our STEM or Professional monthly newsletters.
Arduino weekly newsletter (already subscribed)
Educators can benefit from the ever growing tech that shapes our environment through fun cool projects.
Why not awe your boss with highly innovative ways to help keep your enterprise connected at no extra cost?
Arduino Survey
We'd like to get to know you little better.
Please help us improve by answering this super short optional survey.