Go Down

Topic: bad coding in setCursor example (Read 978 times) previous topic - next topic

keithb1

Feb 04, 2012, 11:37 am Last Edit: Feb 05, 2012, 04:55 pm by keithb1 Reason: 1
The setCursor.pde example has some bad coding:
Code: [Select]
   // 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:
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);



Here is a unified patch:
Code: [Select]

--- /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);



Keith

AWOL

Could you maybe edit one of those code boxes, please?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

keithb1

In what way? I don't understand what you want me to do?
Keith

AWOL

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

keithb1

Ah, good point. It's changed now.
Thanks.
Keith

maniacbug

Best thIng is to open an issue on the google code tracker, and include the patch.

Go Up