example setCursor in LiquidCristal

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.

// these constants won't change.  But you can change the size of

// your LCD using them:
const int numRows = 2;
const int numCols = 16;

I changed this to

const int numRows = 4;
const int numCols = 20;

but the size of my LCD hasn't changed, it still has two rows and 16 columns. Are you sure this changes the size of the LCD?

I hope the example in the Arduino software can be changed.

Don't hold your breath. There are far worse errors that have not been changed after several years of trying.

Don

Hello,

I don't think you can change the size of your LCD with the software. But if you have a bigger LCD you should change the values in the software accordingly. You can make the printed area smaller though. I agree it is a little bit confusing this comment. I will try to make a more clear statement in my version.

Greetings, Jan.

Janz,
You need to report it to the issues list.
That is how bugs are reported and eventually get fixed:

--- bill

That is how bugs are reported and eventually get fixed:

I guess they will fix this one right after they take care of the capacitor in the 'Shiftout' tutorial.

Don

floresta:

That is how bugs are reported and eventually get fixed:

I guess they will fix this one right after they take care of the capacitor in the 'Shiftout' tutorial.

Don

In the past 6-9 months they have actually been pretty responsive to fixes, especially if you provide
the specific updates needed.
Things are much better now that Christian is working on things.

I have already posted this on the issues list on Github. Hope it will be fixed soon. Thanks for your replies. Jan.