Pages: [1]   Go Down
Author Topic: bad coding in setCursor example  (Read 939 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The setCursor.pde example has some bad coding:
Code:
   // 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:
   // 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:
--- /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);


« Last Edit: February 05, 2012, 10:55:14 am by keithb1 » Logged

Keith

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26278
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Could you maybe edit one of those code boxes, please?
Logged

"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.

UK
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Keith

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26278
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

They're identical.
Logged

"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.

UK
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Keith

Seattle, WA
Offline Offline
God Member
*****
Karma: 11
Posts: 673
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Pages: [1]   Go Up
Jump to: