Wiichuck Turret

Wiichuck Controlled Laser and Dual ServoMotor Turret

By: Ryan Goyette and Nick Ferrara

Our project is a wiichuck controlling a servo(vertical) and another servo (horizontal) and a laser at the same time.

The objective of this is to control it with percision.



#include <Wire.h>
#include "nunchuck_funcs.h"
#include <Servo.h>
int loop_cnt=0;
int aveAngle;
byte accx,accy,zbut,cbut,joyx,joyy;
int ledPin = 7;
int angle=90;
Servo myservo2;
Servo myservo;
int pos=0;
int angley=90;

void setup()
{
  myservo.attach(5);
    Serial.begin(19200);
    nunchuck_setpowerpins();
    nunchuck_init(); // send the initilization handshake
    pinMode(7, OUTPUT);
    Serial.print("WiiChuckDemo ready\n");
    pinMode(5, OUTPUT);
 myservo2.attach(6);
    Serial.begin(19200);
    nunchuck_setpowerpins();
    nunchuck_init(); // send the initilization handshake
    pinMode(6, OUTPUT);
    Serial.print("WiiChuckDemo ready\n");
 
}


void loop()
{
    if( loop_cnt > 100 ) { // every 100 msecs get new data
        loop_cnt = 0;

        nunchuck_get_data();

 Serial.print("joyx: "); Serial.print((byte)joyx,DEC);           // print variable values
        Serial.print("\tjoyy: "); Serial.print((byte)joyy,DEC);
 joyx  = nunchuck_joyx();        // get data from wii chuck
        joyy  = nunchuck_joyy();

        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.println((byte)cbut,DEC);
    if(joyx>130&&angle>0)
    {
    angle=angle+1;
  }
    if(joyx<120&&angle<180)
    {
    angle=angle-1;
  }
   
    if(joyy>135&&angley>0)
    {
    angley=angley-1;
  }
    if(joyy<120&&angley<180)
    {
    angley=angley+1;
  }
 
}
   myservo.write(angle);   
    if (zbut==1)
    {digitalWrite(7, HIGH); // this turns the laser on by pressing "z"
    }
      else
      {
       
       digitalWrite(7, LOW);
      }
      myservo2.write(angley);
      
      
    loop_cnt++;
   
}


We encountered problems with the servos twitching. We resolved that by increasing the 
Range of joyx and joyy to +-5.

If we had more time/resources we would want to hook up a speaker to make laser noises
And also add another laser.
Comments