Lcd Keyboard storing X postion before new line Remebering/storing pervious value

Hi all,
I am working on something and got a little problem.
I’ve got a LCD and a PS/2 Keyboard.
and I’m trying to write/type on the LCD.
But the Problem is That I use X (Horizontal Position) to know where I am on the Horizontal place of the screen.
When I go the the next line I reset X so the Cursor is again on the Left of the screen.
The screen is 16 chars wide 0 to 15, if I go over 15 the screen scrolls to see what your writing of course :slight_smile:
when I go to the New line X is 0, so that when I use Backspace, and X=0 it goes to the line above, but just goes to X=15 on the line above.
So I need to find a Way to remember the Number of chars(X) I used on the previous line.

So if you guys would help me out With this that would be really great,
also I know that if type/write more then 16 and push enter the screen doesn’t scroll the the first place on the second line,
This is something I am still working on, so Don’t spoil it for me :slight_smile:
Just need help on a Way to remember the Previous amount of Chars is used on the previous line.

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 8, 7, 6, 5);

#include <PS2Keyboard.h>

const int DataPin = 4;
const int IRQpin = 3;
int x;  //x position on screen
int y;  //y position on screen

PS2Keyboard keyboard;

void setup() {
 delay(1000);
 keyboard.begin(DataPin, IRQpin);
 lcd.begin(16,2);
 Serial.begin(9600);
 Serial.println("keyboard available?");
}

void loop() {
  if (keyboard.available()) {
    char c = keyboard.read();
    if(c == PS2_ENTER){
      y=1;
      x=0;
      lcd.setCursor(x,y);          
    }
    if(x>=15){
      if(!(c == PS2_BACKSPACE)){
      lcd.scrollDisplayLeft();
      }
    }
    if(c == PS2_BACKSPACE && x > 0){
      x--;
      lcd.setCursor(x,y);
      lcd.print(" ");
      
      if(x>15){
      lcd.scrollDisplayRight();
      }
      if(x==0 && y==1){
        y=0;
        x=15;
      }
      
      lcd.setCursor(x,y);      
    }
    else if(!(c == PS2_ENTER)){
      lcd.print(c);
      x++;
    }
    lcd.cursor();
  }
}

Greet,
Duality.

Create an array:

byte charsPerLine[] = {0, 0};

Every time you write to a line, increment the counter for that line:

charsPerLine[0]++; // Wrote a character to line 0

Every time you backspace, decrement the counter for the current line.

At any given time, charsPerLine[n] will contain the number of characters displayed on line n.

Ah,
nice one hadn't thought of that :slight_smile:
I'll try it.

also I know that if type/write more then 16 and push enter the screen doesn't scroll the the first place on the second line,
This is something I am still working on, so Don't spoil it for me

When you give up you can take a look at the LCD Addressing link at http://web.alfredstate.edu/weimandn for some ideas.

Don

I know there Is a certain way the places are addressed on the lcd,
But I'm learning as I go, and if I get stuck, I will most certainly look at the link
Thank :slight_smile:

PaulS, awesome tip it worked
Wana see the code?
I am gonna show it anyway :slight_smile:

//include librarys
#include <LiquidCrystal.h>
#include <PS2Keyboard.h>
//initialize the library interface pins
LiquidCrystal lcd(12,11,8,7,6,5);
PS2Keyboard keyboard;

const int DataPin = 4;
const int IRQpin = 3;
int x;
int y;
int n;
int charsPerLine[] = {0, 0};

void setup(){
  keyboard.begin(DataPin, IRQpin);
  lcd.begin(16,2);
  Serial.begin(9600);
  Serial.println("Keyboard Available?");
  delay(1000);
}

void loop(){
  if(keyboard.available()){
    char c = keyboard.read();
    if(c == PS2_ENTER){
      y=1;
      x=0;
      lcd.setCursor(x,y);
    }
    if(x>=15){
      if(!(c == PS2_BACKSPACE)){
        lcd.scrollDisplayLeft();
      }
    }
    if(c == PS2_BACKSPACE && x>0){
      x--;
      charsPerLine[0]--;
      lcd.setCursor(x,y);
      lcd.print(" ");
      if(x>15){
        lcd.scrollDisplayRight();
      }
      if(x==0 && y==1){
        y=0;
        x=charsPerLine[n];
      }
      lcd.setCursor(x,y);
    }
    else if(!(c == PS2_ENTER)){
      lcd.print(c);
      charsPerLine[0]++;
      x++;
    }
    lcd.cursor();
  }
}

and floresta verry interesting stuff you’ve posted there

now can give update’s on the project or is that not allowed ?
I’ve got to learn to comment my code, really :S
anyhow thanks for the help :slight_smile:

What I did was dirty and quick: fill up the rest of the line with spaces when you strike enter so there is no need to track number of characters per line. This is the end product I made. I wonder if you are making something similar:

Yea I guess you can fill the rest with spaces, in fact I didn't even think I could do it that way.
But I've learned something on Arrays which were my weak point anyway, it works it does the job :slight_smile:

My ultimate goal is to make a Device with a LCD, that I can use as a "Portable" Serial Monitor, that has In/Output Capability.

duality:
My ultimate goal is to make a Device with a LCD, that I can use as a “Portable” Serial Monitor, that has In/Output Capability.

So your goal is to make a device I already made but with a keyboard on it?

Darn you !!! ]:smiley:

The reasons I didn’t go with a full-size keyboards: too large to carry, too old have to get ps/2 ones and I don’t have mini-din sockets in suppliers I typically go.

So instead I made my keypad with multi-tap. Now you tantalized? Maybe you should buy one and check out what you are missing on your project :wink:

http://www.inmojo.com/store/liudr-arduino-and-physics-gadgets/

Mine implements all ANSI escape sequences (when possible) and a lot more. Think about what you want to add to.

And I thought that I had a original Idea :stuck_out_tongue:
It doesn't matter, and please don't let me see your source code, I want to make this myself :slight_smile:
I had a look on your site earlier I like the Idea behind your device :slight_smile:

duality:
please don't let me see your source code, I want to make this myself :slight_smile:

Not a chance :wink:
That's the work of my last summer. It's several thousand lines of code and I didn't write enough comments. I think I've written enough free code and libs (over 10k lines of code) to keep this one to myself.

I think our idea(s) are to enable standard input and output on arduino to make it more like a computer, enable simple printf and scanf if you like C.

ultimately I want to go independently from from a PC or laptop, cause you can't always have one on you :slight_smile:
I've seen something really interesting though, A Basic interpreter for the arduino, could be really interesting to see if I might be able to implement that :slight_smile:

That's my point too, an input/output device for arduino.

Having a serial panel will help free up huge amount of burdens from the main arduino, which will run a basic interpreter.