View unanswered posts | View active topics It is currently Thu Apr 17, 2014 6:36 am






Reply to topic  [ 2 posts ] 
Joystick programming issues 
Author Message
Rookie

Joined: Thu Feb 03, 2011 4:53 pm
Posts: 1
Post Joystick programming issues
I used the base code provided by ROBOTC for Dual Joysticks, and I modified it a little in order to represent a couple of different things. I tried compiling it and it didn't work and I've reviewed it so many times but I cannot see anything wrong with it. I've attached it, but since I have a mac, I cannot change the note section without keeping the code in pattern, so some of it may seem odd, but the actual code is correct and the note section is changed elsewhere that I cannot reach.


Attachments:
2 joystick.c [4.01 KiB]
Downloaded 176 times
Fri Feb 04, 2011 11:55 pm
Profile
Rookie

Joined: Wed Feb 24, 2010 11:43 pm
Posts: 34
Post Re: Joystick programming issues
To make it compile, remove the { after the two joystick lines, and remove one of the } at the end

However... to make it work:
a) remove that same {} pair, also remove the second "while(true) {" and another } at the end...
b) the joy1btn() function now returns true or false, so no need for an ==, (and I don't think it ever returned a 3?)
c) (cosmetic) when you put it all in one loop, (a above) you've got an extra getjoystick
d) (cosmetic) if you are only doing one thing for an if(), you don't need {}...

Portion of your code:
Code:
  while (true)
  {
    getJoystickSettings(joystick);
    motor[motorD] = -joystick.joy1_y2;
    motor[motorE] = joystick.joy1_y1;
    {
     while(true)
     {
        getJoystickSettings(joystick);  // Update Buttons and Joysticks
         if(joy1Btn(3) == 3)                  // If Joy1-Button1 is pressed:
         {
             motor[motorF] = 10;              // Turn Motor A On at full power
         }
        else                            // If Joy1-Button1 is NOT pressed:
        {
            motor[motorF] = 0;                 // Turn Motor A Off
        }
    }
}
  }


should probably be

Code:
  while (true)
  {
    getJoystickSettings(joystick);
    motor[motorD] = -joystick.joy1_y2;
    motor[motorE] = joystick.joy1_y1;

    if(joy1Btn(3))                  // If Joy1-Button3 is pressed:
       motor[motorF] = 10;          // Turn Motor F On at 10% power
    else                            // If Joy1-Button3 is NOT pressed:
      motor[motorF] = 0;            // Turn Motor F Off
   }


Sat Feb 05, 2011 7:17 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.