Go Down

Topic: Error in setCursor example (LiquidCrystal library) (Read 406 times) previous topic - next topic

Johan Alink

The setCursor example is confusing and therefore wrong (examples are there to clarify things, not to confuse  ;) )

In the example (both on the website and in the v0017 download) the setCursor is used as:
Code: [Select]
lcd.setCursor(thisRow,thisCol);
The Reference says the syntax of setCursor is:
Code: [Select]
lcd.setCursor(col, row)
So the example uses different order for column and row parameters :-/

Also the for-next loops are confusing, thisCol counts from 0 to numRows:
Code: [Select]
for (int thisCol = 0; thisCol < numRows; thisCol++) {

and thisRow counts from 0 to numCols:
Code: [Select]
for (int this[b]Row[/b] = 0; thisRow < numCols; thisRow++) {


To clear up things I would suggest the following changes:
Code: [Select]
    // 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);

tigoe

An oversight, we changed the order of the parameters, but not the naming, I'll get that cleaned up for the next version

Go Up