Hello,
I was studying the example "setCursor" and i didn't understand the code. Although it works, the logic behind it was not very clear. I came up with another version which in my mind will do better. Especially for the beginners in Arduino code (which i am) the examples are an important introduction. They need to be as simple as can be.
The original code is:
// include the library code:
#include <LiquidCrystal.h>
// these constants won't change. But you can change the size of
// your LCD using them:
const int numRows = 2;
const int numCols = 16;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(numCols,numRows);
}
void loop() {
// loop from ASCII 'a' to ASCII 'z':
for (int thisLetter = 'a'; thisLetter <= 'z'; thisLetter++) {
// loop over the columns:
for (int thisCol = 0; thisCol < numRows; thisCol++) {
// loop over the rows:
for (int thisRow = 0; thisRow < numCols; thisRow++) {
// set the cursor position:
lcd.setCursor(thisRow,thisCol);
// print the letter:
lcd.write(thisLetter);
delay(200);
}
}
}
}
Look at the statement " lcd.setCursor(thisRow,thisCol);"
row and column are in the wrong place.
My version is:
// include the library code:
#include <LiquidCrystal.h>
// these constants won't change. But you can change the numbers to your
// LCD accordingly:
const int numRows = 2;
const int numCols = 16;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(numCols,numRows);
}
void loop() {
// loop from ASCII 'a' to ASCII 'z':
for (int thisLetter = 'a'; thisLetter <= 'z'; thisLetter++) {
// loop over the rows:
for (int thisRow = 0; thisRow < numRows; thisRow++) {
// loop over the columns:
for (int thisCol = 0; thisCol < numCols; thisCol++) {
// set the cursor position:
lcd.setCursor(thisCol,thisRow);
// print the letter:
lcd.write(thisLetter);
delay(200);
}
}
}
}
I hope the example in the Arduino software can be changed.
Greetings to all, Jan.