I would like to do a simple texteditor with Arduino and 40x2 LCD (no i2c). I wrote a simple code for testing, but I cannot modify the code myself.
Here's my code:
//Simple texteditor for Arduino and 40x2 LCD
#include <LiquidCrystal.h>
#include <SD.h>
LiquidCrystal lcd(13, 11, 10, 9, 8, 7);
const int buttonAPin = 15;
const int buttonBPin = 16;
const int buttonCPin = 17;
String cachedText = "";
void setup() {
lcd.begin(40, 2);
lcd.blink();
pinMode(buttonAPin, INPUT_PULLUP);
pinMode(buttonBPin, INPUT_PULLUP);
pinMode(buttonCPin, INPUT_PULLUP);
}
void loop() {
int buttonAState = digitalRead(buttonAPin);
int buttonBState = digitalRead(buttonBPin);
int buttonCState = digitalRead(buttonCPin);
if (buttonAState == LOW) {
cachedText += "a";
}
if (buttonBState == LOW) {
cachedText += "b";
}
if (buttonCState == LOW) {
cachedText += "c";
}
lcd.setCursor(0, 0);
lcd.print(cachedText);
delay(100);
}
Now, with this code when I press the buttons (a,b,c) many times so that the text fills the whole LCD (40x2), the cursor gets back to position (0,0)and starts overwriting the existing letters in the first row...and I don't want that. I would like it to continue to next row in the LCD just like you would expect in a simple texteditor like this.
I would also like to add 4 navigation buttons (up, down, left, right) to navigate the text that I have written.
Is there anyone who can help me?
Later I would like to have "save text to SD-card" function after the texteditor is finished...
So that you don't overwrite one character over another you basically need to do two actions.
The first is to define the line and position on the LCD of the next character to be typed,
and secondly use a variable as a counter of already typed characters.
The first one uses the " lcd.setCursor(x, y);
where x is the position and Y is the line.
The first position is 0 and the second is 1.......
The first line is 0 and the second is 1.......
After you understand the setCursor(x,y); (@ruilviana) and make the U/D/L/R work, consider using the "underline" character when in "move" mode and the "block" character when in edit mode... you will need to keep track of the character being edited. Sounds like a fun project.
Ruilviana, I undestand what you are trying to say, but I simply cannot translate that to the code...please, could you modify the code?
Aarg, yes, I already printed out those SD-module examples, I'm studying those now! I already managed to save some text to SD-card, yeah! Things are progressing!
Xfpd, I would like to use LCD's lcd.blink()-command to see where the cursor is moving in the text...if that's what you meant...Yes, this is fun project! But all the fun stops when you get stucked...LOL.