The setCursor.pde example has some bad coding:
// 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);
Note that "thisCol < numRows", "thisRow < numCols" are inconsistent and this is corrected in the last line by reversing the variables in the library call. This would be better as follows:
// 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);
Here is a unified patch:
--- /usr/share/arduino/libraries/LiquidCrystal/examples/setCursor/setCursor.pde 2011-10-20 09:04:08.000000000 +0100
+++ setCursor_modified.pde 2012-02-04 09:59:23.000000000 +0000
@@ -54,12 +54,12 @@
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++) {
+ // 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(thisRow,thisCol);
+ lcd.setCursor(thisCol,thisRow);
// print the letter:
lcd.print(thisLetter, BYTE);
delay(200);