LCD_LINE#

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
cpapple123
Posts: 44
Joined: 04 May 2012, 20:20

LCD_LINE#

Post by cpapple123 »

How can I Right text to the LCD using a Variable Line #
I'm building a fun little project and will be trying to build a menu to jog 6 motors. Axis 1-6. My plan is to use the Enter BTN to select what axis the arrow buttons will drive

> Axis 1
Axis 2
Axis 3
Axis 4
Axis 5
Axis 6

I'm still early in the code Maybe I'm going the totally wrong way

Code: Select all

int currentline;            //Current line pointer Memory

task myDrawScreen()
{
 ClearScreen();
 TextOut(12, LCD_LINE1, "6 Axis Robot" , 0x0000);
 TextOut(1, LCD_LINE2, "> Axis 1" , 0x0000);
 TextOut(1, LCD_LINE3, "  Axis 2" , 0x0000);
 TextOut(1, LCD_LINE4, "  Axis 3" , 0x0000);
 TextOut(1, LCD_LINE5, "  Axis 4" , 0x0000);
 TextOut(1, LCD_LINE6, "  Axis 5" , 0x0000);
 TextOut(1, LCD_LINE7, "  Axis 6" , 0x0000);
 currentline =2;
 }

task myMenuPointer()
{
     while (true)
     {
           if (ButtonPressed(BTNCENTER, true))
              {Wait(1000);
              TextOut(1, LCD_LINE2, "  Axis 1" , 0x0000);
              TextOut(1, LCD_LINE3, "> Axis 2" , 0x0000);
      
              currentline = currentline +1;
              NumOut(1, LCD_LINE8, currentline , 0x0000);
              }

      }
}

task main()
{
 Precedes(myDrawScreen, myMenuPointer);
}
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: LCD_LINE#

Post by HaWe »

for a variable line number I am using an array
char LCDline[]={56,48,40,32,24,16,8,0}; // counting 0...7

so you can jump to the line you want to write to by
char i;
TextOut(0, LCD_LINE,.....);
cpapple123
Posts: 44
Joined: 04 May 2012, 20:20

Re: LCD_LINE#

Post by cpapple123 »

Thank you. I will play some with you code. I did find a temporarily solution. I use a case statement and hard coded the 6 scenarios.

Code: Select all

sub myClearline(int i)
{
 switch (i)
 {
   case 1 :
   TextOut(1, LCD_LINE2, "  Axis 1" );
   TextOut(1, LCD_LINE3, "> Axis 2" );
   break;
   case 2 :
   TextOut(1, LCD_LINE3, "  Axis 2" );
   TextOut(1, LCD_LINE4, "> Axis 3" );
   break;
   case 3 :
   TextOut(1, LCD_LINE4, "  Axis 3" );
   TextOut(1, LCD_LINE5, "> Axis 4" );
   break;
   case 4 :
   TextOut(1, LCD_LINE5, "  Axis 4" );
   TextOut(1, LCD_LINE6, "> Axis 5" );
   break;
   case 5 :
   TextOut(1, LCD_LINE6, "  Axis 5" );
   TextOut(1, LCD_LINE7, "> Axis 6" );
   break;
   case 6 :
   TextOut(1, LCD_LINE7, "  Axis 6" );
   TextOut(1, LCD_LINE2, "> Axis 1" );
   break;
 }
}
cpapple123
Posts: 44
Joined: 04 May 2012, 20:20

Re: LCD_LINE#

Post by cpapple123 »

Much cleaner Thank you. Plus got some good practice on arrays :)

Code: Select all

task myMenuPointer()
{
 while (true)
 {
 if (ButtonPressed(BTNCENTER, true))
    {
    Wait(1000);
    TextOut(1, LCDline[currentline], StrCat("  Axis ", NumToStr(currentline)));

    if (currentline<6)
    TextOut(1, LCDline[currentline+1], StrCat("> Axis ", NumToStr(currentline+1)));
    else
    TextOut(1, LCDline[1], StrCat("> Axis ", NumToStr(1)));

    if (currentline<6)
      currentline = currentline+1;
    else
      currentline = 1;
    NumOut(1, LCD_LINE8, currentline );
    }
 }
}
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: LCD_LINE#

Post by mattallen37 »

I use:

Code: Select all

LCD_LINE1 - (line * 8)
For the x axis, I use:

Code: Select all

column * 6
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 0 guests