Go Down

Topic: How to set the cursor on the LCD using a variable? (Read 4779 times) previous topic - next topic


I need to have the cursor move on my LCD based off a variable but what I am trying doesn't work. Is it possible to set the lcd cursor with a variable in the positions?

Here is what won't work for me:
  lcd.setCursor(**varibale goes here**, 0);


Show what you really tried, not:

Code: [Select]

  lcd.setCursor(**varibale goes here**, 0);

Do you get a compile error, or does it compile but not do what you expect?
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics


Here is a line of code from a program of mine:-
Code: [Select]
    lcd.setCursor(4 + menuTitle[m].length(), 1);
That is using a variable to set a cursor.

Post all you code using the code tags so we can see what you are doing wrong.


Code: [Select]

int set;
char ch;

void loop() {
   /////////////////////////String 1 length//////////////////////////////////
   if( Serial.available() ) {
   ch = Serial.read();
   set = ch;
   lcd.setCursor('set', 0);


'set' is a multi byte character constant, "set" is a string.

What you want is just the variable:

Code: [Select]
lcd.setCursor( set, 0);
Forum Mod anyone?


lcd.setCursor(set, 0) doesn't work eiter, i'm getting no print out at all.


lcd.setCursor(col, row) does what it sounds like. Sets the cursor position on the lcd.
The next character printed will be placed at that location.
Your code never prints any characters which is why you never see anything.
It reads a character from the serial port then uses the numeric code of that character to
set the cursor position to that column on row zero.

Have quick read of the LiquidCrystal functions to get a better feel of the
routines available to see what will do what you want.

--- bill


So now you showed us what you have and what is "not working", what is it that you want? You sound like a customer scrolling into a shop and just can't describe to the clerk what you are in the store for. You won't be treated nicely after a while.
Serial LCD keypad panel,phi_prompt user interface library,SDI-12 USB Adapter


Dec 09, 2012, 04:17 am Last Edit: Dec 09, 2012, 08:56 am by bperrybap Reason: 1
One thing you might not be aware of is by default the actual cursor is invisible.
If you want to see the cursor the cursor() function will turn it on.

--- bill


Serial read returns the ASCII value of the character sent. So if you send a 1 then number you recieve is 39, so when you do that right the cursor will move to position 39. Will you be able to see that?


Here is what won't work for me:

turn on the cursor and then go to the spot you want.

Go Up