![]() |
[FTC]: Java in RobotC for TeleOp
I need help with programming. I found that you can use certain Java commands in RobotC. So I thought that I could use the Switch command which worked for some things but I have no idea how to make it work for the buttons in the TeleOp phrase.
The syntax for the Switch command is Code:
switch (variable)http://www.youtube.com/watch?v=RVRPmeccFT0 This is my proof of concept code for Java in RobotC. It is supposed to display what button is being pressed on the NXT screen. Since this was only a proof of concept, only wrote code for Buttons 1-4 on Game controller #1(Logitech Dual action). The purpose of using the Switch command was to shorten up the code and make it less massive instead of using an IF and ELSE command for every button that will be used. Code:
#pragma config(Hubs, S1, HTMotor, HTMotor, HTMotor, HTServo)Mason Tran FTC Team 3385 Lead Programmer |
Re: [FTC]: Java in RobotC for TeleOp
The problem is the button commands you are using. "joystick.joy1_Buttons" doesn't work like Joy1Btn, where it outputs the actual button number. Instead, it outputs numbers to the power of 2, like this:
button 1 = 1 button 2 = 2 button 3 = 4 button 4 = 8 button 5 = 16 button 6 = 32 etc... This is useful to allow for commands where multiple buttons are pressed at once, but can be a pain otherwise. In your script, button 3 should activate case 4, with button 4 activating case 8. Case 3 currently displays when 1 and 2 are pressed togethor, and case 4 displays when button 3 is pressed. |
Re: [FTC]: Java in RobotC for TeleOp
Quote:
In addition, the joy1_buttons int adds the numbers together if multiple buttons are pressed at once (ex if button 3 (button 3 is 4) and button 4 (button 4 is 8) were pressed at the same time, the result in joy1_buttons would be 12). Also, your code would only check to see if a single button is pressed each time the loop runs, because you're using a single switch statement. So, if you had buttons 3 and 4 pressed, the program would only see button 3 as pressed. You may want to try a loop that checks each button, something like... Code:
for(int i=1;i<=12;i++) { |
| All times are GMT -5. The time now is 18:41. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi