#include <math.h>
#include <Wire.h>
#include <WiiChuck.h>
#include <TVout.h>
#include <stdio.h>
#include "notedefs.h"
#include "lib3d.h"
#define SETUP_WIDTH 120
#define WIDTH 119 // visible width...
#define HEIGHT 96
#define SOUND_OUT_PIN 2
#define MAX_ROLL 15 // nunchuck max roll
#define MAX_PITCH 90 // nunchuck max pitch
TVout cTV;
WiiChuck cChuck = WiiChuck();
Scene3D cScene;
int iLeftY = HEIGHT / 2;
int iRightY = HEIGHT / 2;
int angleStart, currentAngle;
int tillerStart = 0;
double angle;
#define CUBE 20
void setup()
{
cChuck.begin();
cChuck.update();
cChuck.calibrateJoy();
cTV.begin(_PAL,SETUP_WIDTH,HEIGHT); //for devices with only 1k sram(m168) use TV.begin(_PAL,128,56)
cTV.clear_screen();
cScene.CreateScene(WIDTH,HEIGHT,&cTV);
cScene.AddCube(0,0,0,CUBE);
}
void loop()
{
char buffer[20];
int iRoll;
float fRollAngle;
int iPitch;
float fPitchAngle;
cTV.delay_frame(1);
cChuck.update();
cTV.clear_screen();
iRoll = cChuck.readRoll();
fRollAngle = (PI * iRoll)/MAX_ROLL;
iPitch = cChuck.readPitch();
fPitchAngle = (PI * iPitch)/MAX_PITCH;
sprintf(buffer,"%d %d",iRoll,iPitch);
cTV.print_str(0,0,buffer);
// cTV.draw_line(0,iLeftY - iRoll, WIDTH, iLeftY + iRoll, 1);
cScene.SetHAngle(fRollAngle);
cScene.SetVAngle(fPitchAngle);
cScene.UpdateDisplay();
if (iRoll > MAX_ROLL)
{
cTV.tone( NOTE_D4 );
}
else if (iRoll < -MAX_ROLL)
{
cTV.tone( NOTE_B4 );
}
else
{
cTV.noTone();
}
/*
Serial.print(", ");
Serial.print(chuck.readPitch());
Serial.print(", ");
Serial.print((int)chuck.readAccelX());
Serial.print(", ");
Serial.print((int)chuck.readAccelY());
Serial.print(", ");
Serial.print((int)chuck.readAccelZ());
// Serial.print(", ");
// Serial.print((int)chuck.readJoyX());
// Serial.print(", ");
// Serial.print((int)chuck.readJoyY());
Serial.println();
*/
}
Nunchuck Controlled 3D cube on TV « Paul's Arduino
January 6, 2011 at 12:16 am
[...] code libraryAnalogue Clocklib3d.cpplib3d.hNunchuck 3DPOV Source codeScrolling Digital ClockThermometer and Clock RSS [...]
Arduino Blog » Blog Archive » Nunchuck Controlled 3D Cube On TV
January 6, 2011 at 5:15 pm
[...] [Paul] took the TVout library, the Wiichuck library and wrote it’s own 3D library. In this way he’s got a nunchuck controlled 3D shape on TV Movement in the nunchuck is detected by the arduino, then the cube is redrawn according to new angle of the controller. 3d wireframe library header and source. Code to tie everything together [...]
Nunchuck Controlled 3D Cube On TV | dev.SquareCows.com
January 7, 2011 at 1:44 am
[...] [Paul] took the TVout library, the Wiichuck library and wrote it’s own 3D library. In this way he’s got a nunchuck controlled 3D shape on TV Movement in the nunchuck is detected by the arduino, then the cube is redrawn according to new angle of the controller. 3d wireframe library header and source. Code to tie everything together [...]