ROBOTC.net forums
http://www.robotc.net/forums/

NXT buttons in Virtual World doesn't work
http://www.robotc.net/forums/viewtopic.php?f=55&t=4952
Page 1 of 1

Author:  MHTS [ Sat Oct 06, 2012 2:42 pm ]
Post subject:  NXT buttons in Virtual World doesn't work

For the FTC competition, our library has a "choice menu" module which displays autonomous strategy choices on the NXT LCD screen and allowing the user to press the left/right arrow buttons to go up and down the menu and press ENTER to select the choice. The code works fine with a real NXT but when running it in Virtual World, the code doesn't work. I have simplified the code to demonstrate the problem.
Code:
/**
    According to nxtFileIODefs.h:
    kNoButton = -1
    kExitButton = 0
    kRightButton = 1
    kLeftButton = 2
    kEnterButton = 3
   
    But in Virtual World:
    kNoButton = -1
    kLeftButton = 1
    kRightButton = 0
    kEnterButton and kExitButton has no effect
*/

task main()
{
    while (true)
    {
        nxtDisplayTextLine(0, "Btn=%x", nNxtButtonPressed);
        wait1Msec(100);
    }
}

Author:  JohnWatson [ Tue Oct 09, 2012 10:32 am ]
Post subject:  Re: NXT buttons in Virtual World doesn't work

We are currently looking into to these button values, but in the meanwhile I would like to make an educational note of some of the differences between the NXT Remote screen in normal ROBOTC operation and Virtual Worlds operation.

Virtual Worlds will support only one program at a time, so you won't be able to use a Program Chooser program to switch between multiple programs once one has been loaded to a Virtual World table. However, you can code a program that does different things depending on which buttons are pressed on the NXT Remote Screen:

Code:
task main()
{
   while   (nNxtButtonPressed == -1)
      { }

      if (nNxtButtonPressed == 1)
         {
          nxtDisplayTextLine(0, "Btn=%x", nNxtButtonPressed);
        wait1Msec(1000);
         }
      
      if (nNxtButtonPressed == 2)
         {
           nxtDisplayTextLine(0, "Btn=%x", nNxtButtonPressed);
             wait1Msec(1000);
         }
         
      if (nNxtButtonPressed == 3)
         {
           nxtDisplayTextLine(0, "Btn=%x", nNxtButtonPressed);
         wait1Msec(1000);
         }

}


What the above code does is sit idle in the first while loop until any button is pressed (a value of -1 for the nNxtButtonPressed means no button is pressed). Once a button is pressed, the NXT displays which button is pressed on the screen for 1 second. The grey button will still cancel the program.

You can tailor-fit a program like this to your individual needs (by calling functions or starting tasks when a specific button is pressed, for example).

For more information on coding the NXT buttons, the NXT display, and all of the other ROBOTC functions for the NXT, please see our wiki.

Author:  MHTS [ Tue Oct 09, 2012 12:24 pm ]
Post subject:  Re: NXT buttons in Virtual World doesn't work

No, it is not a program chooser. One single program implements all the competition strategies and the menu code is to choose what strategy to use. So it is not changing to another program.

Author:  jbflot [ Thu Oct 11, 2012 9:38 am ]
Post subject:  Re: NXT buttons in Virtual World doesn't work

This will be fixed in the next ROBOTC update, coming soon! Thanks.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/