Instantly share code, notes, and snippets.

Embed
What would you like to do?
WiiChuckDemo with 7-Segment Display for button presses
/*
* WiiChuckDemo --
*
* 2008 Tod E. Kurt, http://thingm.com/
*
* with code for 7-Segment Display added by Chris Nolan.ca
* based on https://gist.github.com/3268581
*
*/
#include <Wire.h>
#include "nunchuck_funcs.h"
#include <SoftwareSerial.h>
int loop_cnt=0;
byte accx,accy,zbut,cbut;
int ledPin = 13;
#define SerInToArdu 2
#define SerOutFrmArdu 3
#define wDelay 300
SoftwareSerial mySerialPort(SerInToArdu,SerOutFrmArdu);
String seven_seg;
void setup()
{
pinMode(SerOutFrmArdu,OUTPUT);
mySerialPort.begin(9600);
mySerialPort.print("v");
seven_seg = "x--x";
mySerialPort.print(seven_seg);
Serial.begin(19200);
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_accelx(); // ranges from approx 70 - 182
accy = nunchuck_accely(); // ranges from approx 65 - 173
zbut = nunchuck_zbutton();
cbut = nunchuck_cbutton();
Serial.print("accx: "); Serial.print((byte)accx,DEC);
Serial.print("\taccy: "); Serial.print((byte)accy,DEC);
Serial.print("\tzbut: "); Serial.print((byte)zbut,DEC);
Serial.print("\tcbut: "); Serial.print((byte)cbut,DEC);
if (zbut == 0) {
seven_seg.setCharAt(0, '0');
} else {
seven_seg.setCharAt(0, '1');
};
if (cbut == 0) {
seven_seg.setCharAt(3, '0');
} else {
seven_seg.setCharAt(3, '1');
};
mySerialPort.print(seven_seg);
Serial.print("\t7Seg: "); Serial.println(seven_seg);
}
loop_cnt++;
delay(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment