Page 2 of 2

Re: NXC NXT 2.0 test_release20111215 file error

Posted: 20 Dec 2011, 17:42
by h-g-t
Ah, that explains it!

I did not realise it was treated as a 2D array so ignored all the warnings - thank you.

Re: NXC NXT 2.0 test_release20111215 file error

Posted: 23 Dec 2011, 15:13
by h-g-t
My project requires 5 options to be selected each time it runs. This was a bit of a nuisance, especially when most of the time the same options were used.

So I rewrote the first part to display all the options at once; if these do not have to be changed then I only have to press the middle key.

To change an option, I turn the motor attached to port B to select the option(s) and the right key to change it. Middle key continues on to the rest of the program. Options are stored on an array as +1 or -1.

I put it here just in case anyone else finds it useful. If someone more competent than me can convert this into a re-usable subroutine then please let me know how.

Code: Select all


// Start global variable & constant definitions ------------------------------

  string program = "Program #"; // Store the program name & version
  
  long rotation_end_B;        // Final reading of rotation counter Port B
  long rotation_B;               // For use in parameter selection
   
  int MM_Index = 1;           // Current line/ element
  int MM_Bool[] = {-1,-1,-1,-1,-1,-1}; // Record of options
  string MM_D1 = " ";      // Blank for 9v relay
  string MM_D2 = " ";      // Blank for autofocus on
  string MM_D3 = " ";      // Blank for mirror lock on
  string MM_D4 = " ";      // Blank for exposure bracketing on
  string MM_D5 = " ";      // Blank for limited pano size on
  string Pt = "<<";           // Selection marker


// End of global variable and constant declarations ===========================



task main ()
{

// Set basic parameters --------------------------------------------------

  ClearScreen ();
  PlayTone (3000,500);
  Wait (500);
  TextOut (1,LCD_LINE2,program);
  TextOut (1,LCD_LINE3,"RIGHT KEY CHANGE");
  TextOut (1,LCD_LINE4,"CENTRE KEY END");
  TextOut (1,LCD_LINE5,"MOTOR B = UP/ DOWN");
  TextOut (1,LCD_LINE7,"BATTERY ");
  NumOut (64,LCD_LINE7,BatteryLevel());
  Wait (1000);

  while (ButtonPressed(BTNCENTER,true) == false) {} // End when centre button pressed

  PlayTone (1000,500);
  Wait (1000);

  ResetRotationCount(OUT_B);             // Reset counter on Port B
  Wait (100);                                      // Give sensor time to update

  while (ButtonPressed(BTNCENTER,true) == false) // End when centre button pressed
  {

   ClearScreen ();
   TextOut (1,LCD_LINE1,"< 9v RELAY");       TextOut (72,LCD_LINE1,MM_D1);
   TextOut (1,LCD_LINE2,"AUTOFOCUS");     TextOut (72,LCD_LINE2,MM_D2);
   TextOut (1,LCD_LINE3,"MIRROR LOCK");   TextOut (72,LCD_LINE3,MM_D3);
   TextOut (1,LCD_LINE4,"BRACKETING");    TextOut (72,LCD_LINE4,MM_D4);
   TextOut (1,LCD_LINE5,"LIMITED PANO");  TextOut (72,LCD_LINE5,MM_D5);

   switch(MM_Index)                              // Set pointer location
    {
     case 1: TextOut (84,LCD_LINE1,Pt); break;
     case 2: TextOut (84,LCD_LINE2,Pt); break;
     case 3: TextOut (84,LCD_LINE3,Pt); break;
     case 4: TextOut (84,LCD_LINE4,Pt); break;
     case 5: TextOut (84,LCD_LINE5,Pt); break;
     default: break;
    }
    
   if (ButtonPressed(BTNRIGHT,true) == true)  // Right button pressed?
   {
    PlayTone (1000,500);
    Wait (500);

    MM_Bool[MM_Index] =  MM_Bool[MM_Index] * -1 ; // Change sign

    if (MM_Bool[1] < 0) {MM_D1 = " ";}  else {MM_D1 = "+";}
    if (MM_Bool[2] < 0) {MM_D2 = " ";}  else {MM_D2 = "+";}
    if (MM_Bool[3] < 0) {MM_D3 = " ";}  else {MM_D3 = "+";}
    if (MM_Bool[4] < 0) {MM_D4 = " ";}  else {MM_D4 = "+";}
    if (MM_Bool[5] < 0) {MM_D5 = " ";}  else {MM_D5 = "+";}
   }
   
   rotation_B = MotorRotationCount(OUT_B); // Current reading Port B
   Wait (100);                             // Give sensor time to update
   ResetRotationCount(OUT_B);  // Reset counter on Port B
   Wait (100);                            // Give sensor time to update
   
   if (abs(rotation_B) > 10)         // Ignore small movements
    {
     if (rotation_B < 1) {MM_Index = MM_Index - 1;}    // Decrement index
     else                     {MM_Index = MM_Index + 1;}    // Increment index

     if (MM_Index < 1)   {MM_Index = 5;}   // Wrap to bottom
     if (MM_Index > 5)   {MM_Index = 1;}   // Wrap to top
    }
     
  } // End of While loop


} // main task ended =======================================================
MM_Index.zip
(1.29 KiB) Downloaded 317 times