View unanswered posts | View active topics It is currently Tue Sep 16, 2014 4:30 am






Reply to topic  [ 1 post ] 
LCD menu / paramreters interface code for your consideration 
Author Message
Rookie

Joined: Thu Dec 29, 2011 8:34 pm
Posts: 14
Post LCD menu / paramreters interface code for your consideration
With some help from folks here I have created a nice little system interactively setting parameters using the NXT buttons and LCD. You may find it useful. See enclosed files. Below is a summary of the utility.

Code:
/////////////////////////////////////////////////////////////////////////////
//  params.c
//
// Provides a facility for setting named parameters using the NXT LCD and buttons.
/*   
  In the user code, first each parameter and its possible values are defined using addParam()
  and addParamValue(), then getParams() is called, which starts the interactive
  parameter-setting process. getParams() returns when the user presses the
  Exit button and confirms with the Enter button.
 
    addParam( "Alliance" );    // adds one parameter
    addParamValue( "Red" );    // adds one value option to the most-recently added param
    addParamValue( "Blue" );   // adds one value option to the most-recently added param
       
    getParams();              // starts LCD/button interactive param setting process
    listParams();             // summarizes params and their values on the LCD.   
   
    getParamValueByName( "Alliance" ); // returns INDEX of the selected value option
                                       // e.g. 0 => "Red", 1 => "Blue"
    getParamValueByNumber( 0 );        // returns INDEX of the selected value option
   
 
  This facility does not support entering arbitrary values for parameters, but only
  allows choosing from a preset list of value options that are defined using addParamValue().
 
  After getParams() returns, the user code can then access the values by calling
  either getParamValueByName() or getParamValueByNumber().  Both functions return the
  INDEX of the value of the parameter. If the parameter has four possible values,
  getParamValueBy*() will return 0, 1, 2, or 3, corresponding to the order in which
  the parameter's value was added using addParamValue().

 
  The maximum number of parameters, and the maximum number or value options each
  parameter can have, are limited by two #define macros:
 
    #define MAX_PARAMS (5)        // set these no higher than
    #define MAX_PARAM_VALUES (8)  // what you need!
   
  Setting these determines how much memory is allocated for the parameters, so you
  should set these no higher than what you need.  Each parameter has one string for
  a name and MAX_PARAM_VALUES strings for the options (regardless of how many options
  are actually associated with the parameter), so the above settings would reserve
  45 strings (8+1)*5.
 
  The call to getParams() starts an interactive button-pushing process.  On the LCD,
  the first parameter is shown on one line and its first value option on the next line.
  The ">" arrow points at the parameter name to show that the arrow keys will select
  which parameter is being set.  Pressing Enter moves the ">" arrow to the parameter's
  value, showing that the arrow keys will change the value.  Pressing Enter again goes
  back to the first mode (selecting parameters).
 
  Pressing Exit will show a confirmation screen ("Params OK?").  Pressing Enter means
  "yes," and getParams() will return.  Pressing Exit means "no" and parameter setting
  continues.
 
  Usage example:
   
         task main()
         {
                  
           initParams( );
          
           addParam     ( "Color" );  // param 0
           addParamValue( "Red" );       //   value 0
           addParamValue( "Blue" );      //   value 1
         
           addParam     ( "Side" );  // param 1
           addParamValue( "Left" );      //   value 0
           addParamValue( "Right" );     //   value 1
         
           addParam     ( "Delay" );     // param 2
           addParamValue( "0 sec"  );    //   value 0
           addParamValue( "1 sec"  );    //   value 1
           addParamValue( "2 sec"  );    //   value 2
           addParamValue( "3 sec"  );    //   value 3
           addParamValue( "4 sec"  );    //   value 4
           addParamValue( "5 sec"  );    //   value 5
           addParamValue( "6 sec"  );    //   value 6
           addParamValue( "7 sec"  );    //   value 7
         
           addParam     ( "Mode" );      // param 3
           addParamValue( "ball"  );     //   value 0
           addParamValue( "park"  );     //   value 1
           addParamValue( "nada"  );     //   value 2
         
           getParams ( );  // interactive parameter selection. 
                           // Returns when user finishes selection.
          
           byte color = getParamValueByName( "Color" );
           byte side  = getParamValueByName( "Side" );
           byte delay = getParamValueByName( "Delay" );
           byte mode  = getParamValueByName( "Mode" ); 
 
 
*/
//
/////////////////////////////////////////////////////////////////////////////


Attachments:
File comment: File with task main() that demonstrates the use of params.c
main.c [3.05 KiB]
Downloaded 299 times
File comment: Utility for setting params from LCD using NXT buttons.
params.c [12.84 KiB]
Downloaded 303 times
Sat Jan 07, 2012 11:31 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

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.