View unanswered posts | View active topics It is currently Wed Oct 01, 2014 10:25 pm






Reply to topic  [ 4 posts ] 
"if (joy1btn(btn) !=0)" Help? 
Author Message
Rookie

Joined: Fri Nov 28, 2008 3:44 pm
Posts: 2
Post "if (joy1btn(btn) !=0)" Help?
I am working on my coding and am attempting to configure the 1-10 buttons to perform different functions. The code I am using is,

if (joy1Btn(01)!=0)
{
motor[motorA] = 100;
motor[motorB] = 100;
}
if (joy1Btn(02)!=0)
{
motor[motorA] = -100;
motor[motorB] = -100;
}
if (joy1Btn(03)!=0)
{
motor[motorA] = 0;
motor[motorB] = 0;
}

The area where it has 01, 02 and 03 SHOULD be where you put the number of the button you would like to use, according to the help files. For some reason whenever I attempt to use the code, only button 1 works, and it trys to run every one of these commands at once and starts freaking out.

I have been tearing my hair out over this for a while and any help would be appreciated.


Tue Dec 09, 2008 7:40 pm
Profile
Site Admin
Site Admin

Joined: Wed Jan 24, 2007 10:42 am
Posts: 610
Post Re: "if (joy1btn(btn) !=0)" Help?
Please search the forums to see if your question has been answered before posting a new thread.

viewtopic.php?f=33&t=785

_________________
Timothy Friez
ROBOTC Developer - SW Engineer
tfriez@robotc.net


Wed Dec 10, 2008 10:34 am
Profile
Rookie

Joined: Thu Oct 02, 2008 12:35 pm
Posts: 12
Post Re: "if (joy1btn(btn) !=0)" Help?
nonagood1 wrote:
I am working on my coding and am attempting to configure the 1-10 buttons to perform different functions. The code I am using is,

if (joy1Btn(01)!=0)
{
motor[motorA] = 100;
motor[motorB] = 100;
}
if (joy1Btn(02)!=0)
{
motor[motorA] = -100;
motor[motorB] = -100;
}
if (joy1Btn(03)!=0)
{
motor[motorA] = 0;
motor[motorB] = 0;
}

The area where it has 01, 02 and 03 SHOULD be where you put the number of the button you would like to use, according to the help files. For some reason whenever I attempt to use the code, only button 1 works, and it trys to run every one of these commands at once and starts freaking out.

I have been tearing my hair out over this for a while and any help would be appreciated.


I think you should try doing it like this:
Code:
if (joy1Btn(01)==1)
    {
      motor[motorA] = 100;
      motor[motorB] = 100;
    }
if (joy1Btn(02)==1)
    {
      motor[motorA] = -100;
      motor[motorB] = -100;
    }
if (joy1Btn(03)==1)
    {
      motor[motorA] = 0;
      motor[motorB] = 0;
    }


I have had some weird things happen when I enter code one way, when you can enter it another. If this does, fix it, then it means that your RobotC was just acting up. If this does not fix it, then can you post your entire code? There may be another problem that is existing within another part of your code, and without knowing what the rest of it is, i cannot know for sure.

_________________
Gracious Professionalism. Their standard, our standard.


Mon Jan 05, 2009 5:54 pm
Profile
Rookie

Joined: Sun Nov 16, 2008 3:07 pm
Posts: 45
Post Re: "if (joy1btn(btn) !=0)" Help?
I'll echo tfriez's advice above to go read our earlier posts on this topic at
viewtopic.php?f=33&t=785

adding the ==1 isn't going to help, and in fact I think it will work even less well, since in addition to the operator precedence problem discussed at significant length in the referenced thread, you are going to be doing something like
if (x & 1 << 3 ==1 )
and even on a good day, it won't equal 1. i.e. even if things are properly parenthesized:
if ((x & (1 << 3)) ==1 )
it isn't going to ==1. if the button is pressed, (x & (1 << 3)) is going to be 8, not 1. (this would be an example for button 4)

Management summary:
1. Follow tfriez advice and don't say == anything when using the joy2btn(b) macro.
2. Understand my explanation of the operator precedence issues that make the #define not work when used with ==.

Extra credit:
3. write your own MyJoy2Btn(b) macro that tolerates the use of ==

Best regards,
David Fort


Tue Jan 06, 2009 8:26 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 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.