[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4756: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3891)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4758: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3891)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4759: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3891)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4760: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3891)
Hacker.instanet.net • View topic - 16X2 LCD

16X2 LCD

Anything Arduino

16X2 LCD

Postby DaveE » Sun May 27, 2012 11:57 pm

Tim,
I bought an LCD/keypad shield at TRW yesterday. This is phase II of my stepper motor project that I have been working on. I am trying to write 2 int variables to the LCD in positions 7,0 and 15,0. The variable is an int that is incremented each time a button is pressed. The numbers are displayed correctly when stepping up from position 0 to 9 and from 9 to 0. When I go to 10 or> the number is displayed correctly until stepping down from 10 to 9 which leaves the 0 and changes the 1 to a 9 for a display of 90. This pattern is repeated all the way down to 0 which displays 00. (80, 70, 60...) I tried to print a " " (double space) before printing the variable to try to clear the display but I got strange behavior. ie printed a second variable next to the cursor position called. Didn't understand that at all.
code here:
#include <LiquidCrystal.h>

LiquidCrystal lcd( 8, 9, 4, 5, 6, 7 );
int upbutton = A3;
int dwnbutton = A5;
int upbuttonState = 0;
int dwnbuttonState = 0;
int count = 0;

void setup()
{
pinMode(upbutton, INPUT); //assign upbutton to an input
pinMode(dwnbutton, INPUT); //assign dwnbutton to an input
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("Front=");
lcd.setCursor(9,0);
lcd.print("Rear=");
lcd.setCursor(0,1);
lcd.print("1_");
lcd.setCursor(6,1);
lcd.print("2_");
lcd.setCursor(12,1);
lcd.print("3_");
}

void loop()
{
upbuttonState = digitalRead(upbutton);
delay(50);
if (upbuttonState ==HIGH) {
++count;
lcd.setCursor(6,0);
lcd.print(count);
}
else {
lcd.setCursor(6,0);
lcd.print (count);
}
dwnbuttonState = digitalRead(dwnbutton);
delay(50);
if (dwnbuttonState ==HIGH) {
--count;
lcd.setCursor(6,0);
lcd.print (count);
}
else {
lcd.setCursor(6,0);
lcd.print (count);
}
// your main loop code here...
}
---The above is only for the variable displayed after the characters "Front="
I need a way of either creating a leading null character for the single digit numbers or some other way to account for the missing character when decrementing from a 2 digit to a 1 digit variable.

Hope you can help. I am new to mcu's and feel totally lost.

Dave E.
DaveE
 
Posts: 3
Joined: Sun May 27, 2012 11:24 pm

Re: 16X2 LCD

Postby Tim Laren » Mon May 28, 2012 9:42 am

Display a line of spaces maybe 4 characters at the location, then the number at that location.
When you print to the screen, it does not clear. If you just add a few spaces after the number it may also work for you.

Tim

Note: I got distracted, If you want some code I will a little later today.
Image
Tim Laren
Site Admin
 
Posts: 137
Joined: Thu Mar 04, 2010 8:25 pm

Re: 16X2 LCD

Postby DaveE » Mon May 28, 2012 11:30 am

Tim,
I tried this:
{
upbuttonState = digitalRead(upbutton);
delay(50);
if (upbuttonState ==HIGH) {
++count;
lcd.setCursor(6,0);
lcd.print(" ")// added this line to try to clear the lcd before printing (count)
lcd.print(count);
}

But I got weird results. It re-rote the variable a second time two space to the right of the original print. I think the ++ somehow incremented the lcd.setCursor as well as the variable (count)?? Is that possible?

I really don't know what I am doing!

Dave E
DaveE
 
Posts: 3
Joined: Sun May 27, 2012 11:24 pm

Re: 16X2 LCD

Postby Tim Laren » Mon May 28, 2012 4:23 pm

Image
Tim Laren
Site Admin
 
Posts: 137
Joined: Thu Mar 04, 2010 8:25 pm

Re: 16X2 LCD

Postby DaveE » Mon May 28, 2012 5:37 pm

Now I understand that I did not reset the cursor position after writing the space chrs. In the meantime I came up with this:
upbuttonState = digitalRead(upbutton);
delay(50);
if (upbuttonState ==HIGH) {
++count;
lcd.setCursor(6,0);
if (count >= 10) lcd.print(count);
}
else {
lcd.setCursor(6,0);
lcd.print(" ");
lcd.setCursor(6,0);
lcd.print (count);
}

It seems to work OK but seems a little brute force. I just could not figure out how to print the variable "count" and 2 spaces in one lcd.print line. Seems like there should be a way to print a variable and some text after it with one instruction but I can't figure it out.

Thanks for your help,

Dave E
DaveE
 
Posts: 3
Joined: Sun May 27, 2012 11:24 pm

Re: 16X2 LCD

Postby Steve_C » Mon May 28, 2012 7:45 pm

Dave, I have some information that will help you understand the LCD's better.
Go to this link and read up on the standards.
You can send commands to clear the screen and much more with this information.
I built up the basic LCD breadboard control using rotatory switches and learned how to get it all to work.
I then used an ATTiny85 to drive a 595 ic and could send any text to a 16x1 LCD which is harder due to the adressing.

I hope this PDF helps.
Google the 2nd one witch is lcd2.pdf to read more.


Steve
Steve_C
 
Posts: 6
Joined: Fri Dec 09, 2011 8:09 am

Re: 16X2 LCD

Postby Steve_C » Tue Sep 11, 2012 5:36 am

Here is some LCD info for those wanting to use the non I2C types
http://lcd-linux.sourceforge.net/pdfdocs/lcd1.pdf
http://lcd-linux.sourceforge.net/pdfdocs/lcd2.pdf

I posted these on AVRfreaks.net as well.

These 2 documents are very helpful for figuring out how to talk and hook up to the different types.

Steven
Steve_C
 
Posts: 6
Joined: Fri Dec 09, 2011 8:09 am


Return to Arduino

Who is online

Users browsing this forum: No registered users and 3 guests

cron