Pages: [1]   Go Down
Author Topic: How to set the cursor on the LCD using a variable?  (Read 1026 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 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);
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Show what you really tried, not:

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

Do you get a compile error, or does it compile but not do what you expect?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 508
Posts: 31436
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is a line of code from a program of mine:-
Code:
    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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
int set;
char ch;

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

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 53
Posts: 1785
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

What you want is just the variable:

Code:
lcd.setCursor( set, 0);
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Dallas, TX USA
Offline Offline
Edison Member
*
Karma: 47
Posts: 2334
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
http://arduino.cc/en/Reference/LiquidCrystal

--- bill
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 64
Posts: 6893
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Dallas, TX USA
Offline Offline
Edison Member
*
Karma: 47
Posts: 2334
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Bruce,
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
« Last Edit: December 09, 2012, 02:56:38 am by bperrybap » Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 508
Posts: 31436
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Here is what won't work for me:

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

Pages: [1]   Go Up
Jump to: