N64 controller to control 4 servo motors

Hey

Im just starting to work with arduinos and I having an issue. I have gotten n64 controller to work with a servo motor but i can't figure out a way to make the servo motor not reset with the position of the joystick because i want to control another servo on the other axis of the n64 controllers joystick along with having the first servo stay at its location.

Here is my code i based it off the knob/N64 code i find. there is more to it just ran out of room

void loop()
{
int i;
unsigned char data, addr;

// Command to send to the gamecube
// The last bit is rumble, flip it to rumble
// yes this does need to be inside the loop, the
// array gets mutilated when it goes through N64_send
unsigned char command[] = {0x01};

// don't want interrupts getting in the way
noInterrupts();
// send those 3 bytes
N64_send(command, 1);
// read in data and dump it to N64_raw_dump
N64_get();
// end of time sensitive code
interrupts();

// translate the data in N64_raw_dump to something useful
translate_raw_data();

for (i=0; i<16; i++) {
Serial.print(N64_raw_dump*, DEC);*

  • }*

  • Serial.print(' ');*

  • Serial.print(N64_status.stick_x, DEC);*

  • Serial.print(' ');*

  • Serial.print(N64_status.stick_y, DEC);*

  • Serial.print(" \n");*

  • // Serial.print(" Stick X:");*
    // Serial.print(N64_status.stick_x, DEC);

  • // Serial.print(" Stick Y:");*
    //Serial.println(N64_status.stick_y, DEC);

  • // DEBUG: print it*

  • //print_N64_status();*

  • delay(25);*

  • val = map(N64_status.stick_y , -90, 90, 0, 180);*

  • myservo.write(val);*

  • delay(15);*
    }

You need to read this before posting.

Please use the code tag (the # button)

void loop()
{
    int i;
    unsigned char data, addr;

    // Command to send to the gamecube
    // The last bit is rumble, flip it to rumble
    // yes this does need to be inside the loop, the
    // array gets mutilated when it goes through N64_send
    unsigned char command[] = {0x01};

    // don't want interrupts getting in the way
    noInterrupts();
    // send those 3 bytes
    N64_send(command, 1);
    // read in data and dump it to N64_raw_dump
    N64_get();
    // end of time sensitive code
    interrupts();

    // translate the data in N64_raw_dump to something useful
    translate_raw_data();

   for (i=0; i<16; i++) {
       Serial.print(N64_raw_dump, DEC);
    }
    Serial.print(' ');
    Serial.print(N64_status.stick_x, DEC);
    Serial.print(' ');
    Serial.print(N64_status.stick_y, DEC);
    Serial.print(" \n");
   //   Serial.print("         Stick X:");
 //   Serial.print(N64_status.stick_x, DEC);
  //  Serial.print("         Stick Y:");
//Serial.println(N64_status.stick_y, DEC);


    // DEBUG: print it
    //print_N64_status();
    delay(25);
    
    val = map(N64_status.stick_y , -90, 90, 0, 180);
   myservo.write(val);
   delay(15);
}

Also. You code only contains the code to move one server "myservo".

Please post the code with 2 servo's that you say doesn't work.

If your code is too big to post (which seems odd as the limit is 9000 or more characters), upload your ino file

@luisilva

Sorry, it looks like we both posted at the same time :wink:

I believe that to the people that don't care about the rules and don't care about read the rules don't deserve a answer different that "read the rules". I read the rules before starting post why they don't need to read it?

click the MODIFY button in the upper right of the post window.
Highlight all you code.
click the "#" CODE TAGS button on the toolbar above just to the left of the QUOTE button.
click SAVE (at the bottom).
When you post code on the forum, please make a habit of using the code tags "#" button.

(and read the rules....)

Here is the code i figured out the motor issue and it resetting. another thing i am thinking since i can control two motors on a joystick can i control another set when the A button (N64_status.data2) is pressed and held. any tips thanks and sorry for not following the rules im new to the forums.

void loop()
{
    int i;
    unsigned char data, addr;

    // Command to send to the gamecube
    // The last bit is rumble, flip it to rumble
    // yes this does need to be inside the loop, the
    // array gets mutilated when it goes through N64_send
    unsigned char command[] = {0x01};

    // don't want interrupts getting in the way
    noInterrupts();
    // send those 3 bytes
    N64_send(command, 1);
    // read in data and dump it to N64_raw_dump
    N64_get();
    // end of time sensitive code
    interrupts();

    // translate the data in N64_raw_dump to something useful
    translate_raw_data();

   for (i=0; i<16; i++) {
       Serial.print(N64_raw_dump[i], BIN);
    }
    Serial.print(' ');
    Serial.print(N64_status.stick_x, BIN);
    Serial.print(' ');
    Serial.print(N64_status.stick_y, BIN);
    Serial.print(" \n");
   //   Serial.print("         Stick X:");
 //   Serial.print(N64_status.stick_x, BIN);
  //  Serial.print("         Stick Y:");
//Serial.println(N64_status.stick_y, BIN);
{
  if (N64_status.data1 == LOW)
    controlServoX();
    controlServoY();
  else
    controlServoX2();
    controlServoY2();  
    
    // DEBUG: print it
    //print_N64_status();
    delay(25);   
}

void controlServoX) {
  
  if (N64_status.stick_x > 10 && currentServoPosition >=0)
 {
  currentServoPosition = currentServoPosition - 90; //can change the number to make it move quicker
 }
 else if (N64_status.stick_x > 90 && currentServoPosition >= 0){
  //Do nothing the servo is already at its max
 }
 else if (N64_status.stick_x < -10 && currentServoPosition < 180){
  currentServoPosition = currentServoPosition +  15; //can change the number to make it move quicker
 }
 else if (N64_status.stick_x < -10 && currentServoPosition >= 180){
  //Do nothing the servo is already at its max
 }
 else{
  //Do nothing Stick is roughly centre
 }
 myservo.write(currentServoPosition);
}

void controlServoY() {
  
  if (N64_status.data1 == LOW) 
  
  if (N64_status.stick_y > 10 && currentServoPosition >=0)
 {
  currentServoPosition = currentServoPosition - 90; //can change the number to make it move quicker
 }
 else if (N64_status.stick_y > 90 && currentServoPosition >= 0){
  //Do nothing the servo is already at its max
 }
 else if (N64_status.stick_y < -10 && currentServoPosition < 180){
  currentServoPosition = currentServoPosition +  15; //can change the number to make it move quicker
 }
 else if (N64_status.stick_y < -10 && currentServoPosition >= 180){
  //Do nothing the servo is already at its max
 }
 else{
  //Do nothing Stick is roughly centre
 }
 myservo1.write(currentServoPosition);
}

void controlServoX2() {
  
  if (N64_status.data1 == HIGH) 
  
  if (N64_status.stick_x > 10 && currentServoPosition >=0)
 {
  currentServoPosition = currentServoPosition - 90; //can change the number to make it move quicker
 }
 else if (N64_status.stick_x > 90 && currentServoPosition >= 0){
  //Do nothing the servo is already at its max
 }
 else if (N64_status.stick_x < -10 && currentServoPosition < 180){
  currentServoPosition = currentServoPosition +  15; //can change the number to make it move quicker
 }
 else if (N64_status.stick_x < -10 && currentServoPosition >= 180){
  //Do nothing the servo is already at its max
 }
 else{
  //Do nothing Stick is roughly centre
 }
 myservo2.write(currentServoPosition);
}

void controlServoY2() {
  
  if (N64_status.data1 == HIGH) 
  
  if (N64_status.stick_y > 10 && currentServoPosition >=0)
 {
  currentServoPosition = currentServoPosition - 90; //can change the number to make it move quicker
 }
 else if (N64_status.stick_y > 90 && currentServoPosition >= 0){
  //Do nothing the servo is already at its max
 }
 else if (N64_status.stick_y < -10 && currentServoPosition < 180){
  currentServoPosition = currentServoPosition +  15; //can change the number to make it move quicker
 }
 else if (N64_status.stick_y < -10 && currentServoPosition >= 180){
  //Do nothing the servo is already at its max
 }
 else{
  //Do nothing Stick is roughly centre
 }
 myservo3.write(currentServoPosition);
}
}

Figure out the code thanks if anyone needs it just ask