|
Page 1 of 1
|
[ 4 posts ] |
|
"if (joy1btn(btn) !=0)" Help?
| Author |
Message |
|
nonagood1
Rookie
Joined: Fri Nov 28, 2008 3:44 pm Posts: 2
|
 "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 |
|
 |
|
tfriez
Site Admin
Joined: Wed Jan 24, 2007 10:42 am Posts: 537
|
 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 |
|
 |
|
EastBots
Rookie
Joined: Thu Oct 02, 2008 12:35 pm Posts: 12
|
 Re: "if (joy1btn(btn) !=0)" Help?
I think you should try doing it like this: 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 |
|
 |
|
david fort
Rookie
Joined: Sun Nov 16, 2008 3:07 pm Posts: 45
|
 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 |
|
|
|
Page 1 of 1
|
[ 4 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 3 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
|
|