Go Down

Topic: Unexpected results from arrays (Read 175 times) previous topic - next topic

breagle

Hello and thank you for any feed back in advanced. I am getting unexpected results printing on my serial monitor. The unitNames[][] is not printing correctly. I am not sure if is a coding issue or a memory issue. I am using a Mega.

Code: [Select]
String houseCodes[16] = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P"};

String unitCodes[16] = {"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16"};

String unitIDs[16][16] = {
                    {"A1","B1","C1","D1","E1","F1","G1","H1","I1","J1","K1","L1","M1","N1","O1","P1"},
                    {"A2","B2","C2","D2","E2","F2","G2","H2","I2","J2","K2","L2","M2","N2","O2","P2"},
                    {"A3","B3","C3","D3","E3","F3","G3","H3","I3","J3","K3","L3","M3","N3","O3","P3"},
                    {"A4","B4","C4","D4","E4","F4","G4","H4","I4","J4","K4","L4","M4","N4","O4","P4"},
                    {"A5","B5","C5","D5","E5","F5","G5","H5","I5","J5","K5","L5","M5","N5","O5","P5"},
                    {"A6","B6","C6","D6","E6","F6","G6","H6","I6","J6","K6","L6","M6","N6","O6","P6"},
                    {"A7","B7","C7","D7","E7","F7","G7","H7","I7","J7","K7","L7","M7","N7","O7","P7"},
                    {"A8","B8","C8","D8","E8","F8","G8","H8","I8","J8","K8","L8","M8","N8","O8","P8"},
                    {"A9","B9","C9","D9","E9","F9","G9","H9","I9","J9","K9","L9","M9","N9","O9","P9"},
                    {"A10","B10","C10","D10","E10","F10","G10","H10","I10","J10","K10","L10","M10","N10","O10","P10"},
                    {"A11","B11","C11","D11","E11","F11","G11","H11","I11","J11","K11","L11","M11","N11","O11","P11"},
                    {"A12","B12","C12","D12","E12","F12","G12","H12","I12","J12","K12","L12","M12","N12","O12","P12"},
                    {"A13","B13","C13","D13","E13","F13","G13","H13","I13","J13","K13","L13","M13","N13","O13","P13"},
                    {"A14","B14","C14","D14","E14","F14","G14","H14","I14","J14","K14","L14","M14","N14","O14","P14"},
                    {"A15","B15","C15","D15","E15","F15","G15","H15","I15","J15","K15","L15","M15","N15","O15","P15"},
                    {"A16","B16","C16","D16","E16","F16","G16","H16","I16","J16","K16","L16","M16","N16","O16","P16"}
};

String unitNames[16][16] = {
                    {"empty unit a" , "empty unit b" , "empty unit c" , "empty unit d" , "empty unit e" , "empty unit f" , "empty unit g" , "empty unit h" , "empty unit i" , "empty unit j" , "empty unit k" , "empty unit l" , "empty unit m" , "empty unit n" , "empty unit o" , "empty unit p"},
                    {"empty unit a" , "empty unit b" , "empty unit c" , "empty unit d" , "empty unit e" , "empty unit f" , "empty unit g" , "empty unit h" , "empty unit i" , "empty unit j" , "empty unit k" , "empty unit l" , "empty unit m" , "empty unit n" , "empty unit o" , "empty unit p"},
                    {"empty unit a" , "empty unit b" , "empty unit c" , "empty unit d" , "empty unit e" , "empty unit f" , "empty unit g" , "empty unit h" , "empty unit i" , "empty unit j" , "empty unit k" , "empty unit l" , "empty unit m" , "empty unit n" , "empty unit o" , "empty unit p"},
                    {"empty unit a" , "empty unit b" , "empty unit c" , "empty unit d" , "empty unit e" , "empty unit f" , "empty unit g" , "empty unit h" , "empty unit i" , "empty unit j" , "empty unit k" , "empty unit l" , "empty unit m" , "empty unit n" , "empty unit o" , "empty unit p"},
                    {"empty unit a" , "empty unit b" , "empty unit c" , "empty unit d" , "empty unit e" , "empty unit f" , "empty unit g" , "empty unit h" , "empty unit i" , "empty unit j" , "empty unit k" , "empty unit l" , "empty unit m" , "empty unit n" , "empty unit o" , "empty unit p"},
                    {"empty unit a" , "empty unit b" , "empty unit c" , "empty unit d" , "empty unit e" , "empty unit f" , "empty unit g" , "empty unit h" , "empty unit i" , "empty unit j" , "empty unit k" , "empty unit l" , "empty unit m" , "empty unit n" , "empty unit o" , "empty unit p"},
                    {"empty unit a" , "empty unit b" , "empty unit c" , "empty unit d" , "empty unit e" , "empty unit f" , "empty unit g" , "empty unit h" , "empty unit i" , "empty unit j" , "empty unit k" , "empty unit l" , "empty unit m" , "empty unit n" , "empty unit o" , "empty unit p"},
                    {"empty unit a" , "empty unit b" , "empty unit c" , "empty unit d" , "empty unit e" , "empty unit f" , "empty unit g" , "empty unit h" , "empty unit i" , "empty unit j" , "empty unit k" , "empty unit l" , "empty unit m" , "empty unit n" , "empty unit o" , "empty unit p"},
                    {"empty unit a" , "empty unit b" , "empty unit c" , "empty unit d" , "empty unit e" , "empty unit f" , "empty unit g" , "empty unit h" , "empty unit i" , "empty unit j" , "empty unit k" , "empty unit l" , "empty unit m" , "empty unit n" , "empty unit o" , "empty unit p"},
                    {"empty unit a" , "empty unit b" , "empty unit c" , "empty unit d" , "empty unit e" , "empty unit f" , "empty unit g" , "empty unit h" , "empty unit i" , "empty unit j" , "empty unit k" , "empty unit l" , "empty unit m" , "empty unit n" , "empty unit o" , "empty unit p"},
                    {"empty unit a" , "empty unit b" , "empty unit c" , "empty unit d" , "empty unit e" , "empty unit f" , "empty unit g" , "empty unit h" , "empty unit i" , "empty unit j" , "empty unit k" , "empty unit l" , "empty unit m" , "empty unit n" , "empty unit o" , "empty unit p"},
                    {"empty unit a" , "empty unit b" , "empty unit c" , "empty unit d" , "empty unit e" , "empty unit f" , "empty unit g" , "empty unit h" , "empty unit i" , "empty unit j" , "empty unit k" , "empty unit l" , "empty unit m" , "empty unit n" , "empty unit o" , "empty unit p"},
                    {"empty unit a" , "empty unit b" , "empty unit c" , "empty unit d" , "empty unit e" , "empty unit f" , "empty unit g" , "empty unit h" , "empty unit i" , "empty unit j" , "empty unit k" , "empty unit l" , "empty unit m" , "empty unit n" , "empty unit o" , "empty unit p"},
                    {"empty unit a" , "empty unit b" , "empty unit c" , "empty unit d" , "empty unit e" , "empty unit f" , "empty unit g" , "empty unit h" , "empty unit i" , "empty unit j" , "empty unit k" , "empty unit l" , "empty unit m" , "empty unit n" , "empty unit o" , "empty unit p"},
                    {"empty unit a" , "empty unit b" , "empty unit c" , "empty unit d" , "empty unit e" , "empty unit f" , "empty unit g" , "empty unit h" , "empty unit i" , "empty unit j" , "empty unit k" , "empty unit l" , "empty unit m" , "empty unit n" , "empty unit o" , "empty unit p"},
                    {"empty unit a" , "empty unit b" , "empty unit c" , "empty unit d" , "empty unit e" , "empty unit f" , "empty unit g" , "empty unit h" , "empty unit i" , "empty unit j" , "empty unit k" , "empty unit l" , "empty unit m" , "empty unit n" , "empty unit o" , "empty unit p"}
};

     

     
void setup() {
    Serial.begin(115200);
    delay(20);
   
    Serial.println("   ");
    Serial.println("   ");
    Serial.println("   ");
    Serial.println("   ");
    Serial.println("   ");
    Serial.println("   ");
   
    for (int thisHouseCodeIndex = 0; thisHouseCodeIndex < 16; thisHouseCodeIndex++){
        for (int thisUnitCodeIndex = 0; thisUnitCodeIndex < 16; thisUnitCodeIndex++){
            Serial.print("HouseCode: ");
            //String myHouseCode = houseCodes[thisHouseCodeIndex];
            Serial.print(houseCodes[thisHouseCodeIndex]);
            delay(20);
            Serial.print("   ");
           
            Serial.print("UnitCode: ");
         //   String myUnitCode = unitCodes[thisUnitCodeIndex];
            Serial.print(unitCodes[thisUnitCodeIndex]);
            delay(20);
            Serial.print("   ");
           
            Serial.print("UnitID: ");
            String myUnitID = unitIDs[thisUnitCodeIndex][thisHouseCodeIndex];
            Serial.print(unitIDs[thisUnitCodeIndex][thisHouseCodeIndex]);
            delay(20);
            Serial.print("   ");
           
            Serial.print("UnitName: ");
        //   String myUnitName = unitNames[thisUnitCodeIndex][thisHouseCodeIndex];
            Serial.print(unitNames[thisUnitCodeIndex][thisHouseCodeIndex]);
            delay(20);
            Serial.print("   ");
         
            Serial.println("   ");
            delay(20);
        }
        Serial.println("   "); //---House Code: " + houseCode[i]+" ---");
        delay(20);
    }
}

void loop() {
}

MorganS

So what does it actually print?

You are going to have a lot of problems if you ever decide to change the number of rows or columns in your big arrays. If you do a search-replace for "16" then how do you know which one is the rows and which is the columns?

Give the two constants names. Always use the names in the code.
"The problem is in the code you didn't post."

DKWatson

Start with little steps, then big steps. This works,
Code: [Select]
String houseCodes[16] = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P"};

String unitCodes[16] = {"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16"};

String unitIDs[16][16] = {
                    {"A1","B1","C1","D1","E1","F1","G1","H1","I1","J1","K1","L1","M1","N1","O1","P1"},
                    {"A2","B2","C2","D2","E2","F2","G2","H2","I2","J2","K2","L2","M2","N2","O2","P2"},
                    {"A3","B3","C3","D3","E3","F3","G3","H3","I3","J3","K3","L3","M3","N3","O3","P3"},
                    {"A4","B4","C4","D4","E4","F4","G4","H4","I4","J4","K4","L4","M4","N4","O4","P4"},
                    {"A5","B5","C5","D5","E5","F5","G5","H5","I5","J5","K5","L5","M5","N5","O5","P5"},
                    {"A6","B6","C6","D6","E6","F6","G6","H6","I6","J6","K6","L6","M6","N6","O6","P6"},
                    {"A7","B7","C7","D7","E7","F7","G7","H7","I7","J7","K7","L7","M7","N7","O7","P7"},
                    {"A8","B8","C8","D8","E8","F8","G8","H8","I8","J8","K8","L8","M8","N8","O8","P8"},
                    {"A9","B9","C9","D9","E9","F9","G9","H9","I9","J9","K9","L9","M9","N9","O9","P9"},
                    {"A10","B10","C10","D10","E10","F10","G10","H10","I10","J10","K10","L10","M10","N10","O10","P10"},
                    {"A11","B11","C11","D11","E11","F11","G11","H11","I11","J11","K11","L11","M11","N11","O11","P11"},
                    {"A12","B12","C12","D12","E12","F12","G12","H12","I12","J12","K12","L12","M12","N12","O12","P12"},
                    {"A13","B13","C13","D13","E13","F13","G13","H13","I13","J13","K13","L13","M13","N13","O13","P13"},
                    {"A14","B14","C14","D14","E14","F14","G14","H14","I14","J14","K14","L14","M14","N14","O14","P14"},
                    {"A15","B15","C15","D15","E15","F15","G15","H15","I15","J15","K15","L15","M15","N15","O15","P15"},
                    {"A16","B16","C16","D16","E16","F16","G16","H16","I16","J16","K16","L16","M16","N16","O16","P16"}
};

//String unitNames[16][16] = {
String unitNames[16] =
                    {"empty unit a" , "empty unit b" , "empty unit c" , "empty unit d" , "empty unit e" , "empty unit f" , "empty unit g" , "empty unit h" , "empty unit i" , "empty unit j" , "empty unit k" , "empty unit l" , "empty unit m" , "empty unit n" , "empty unit o" , "empty unit p"};//,
/*                    {"empty unit a" , "empty unit b" , "empty unit c" , "empty unit d" , "empty unit e" , "empty unit f" , "empty unit g" , "empty unit h" , "empty unit i" , "empty unit j" , "empty unit k" , "empty unit l" , "empty unit m" , "empty unit n" , "empty unit o" , "empty unit p"},
                    {"empty unit a" , "empty unit b" , "empty unit c" , "empty unit d" , "empty unit e" , "empty unit f" , "empty unit g" , "empty unit h" , "empty unit i" , "empty unit j" , "empty unit k" , "empty unit l" , "empty unit m" , "empty unit n" , "empty unit o" , "empty unit p"},
                    {"empty unit a" , "empty unit b" , "empty unit c" , "empty unit d" , "empty unit e" , "empty unit f" , "empty unit g" , "empty unit h" , "empty unit i" , "empty unit j" , "empty unit k" , "empty unit l" , "empty unit m" , "empty unit n" , "empty unit o" , "empty unit p"},
                    {"empty unit a" , "empty unit b" , "empty unit c" , "empty unit d" , "empty unit e" , "empty unit f" , "empty unit g" , "empty unit h" , "empty unit i" , "empty unit j" , "empty unit k" , "empty unit l" , "empty unit m" , "empty unit n" , "empty unit o" , "empty unit p"},
                    {"empty unit a" , "empty unit b" , "empty unit c" , "empty unit d" , "empty unit e" , "empty unit f" , "empty unit g" , "empty unit h" , "empty unit i" , "empty unit j" , "empty unit k" , "empty unit l" , "empty unit m" , "empty unit n" , "empty unit o" , "empty unit p"},
                    {"empty unit a" , "empty unit b" , "empty unit c" , "empty unit d" , "empty unit e" , "empty unit f" , "empty unit g" , "empty unit h" , "empty unit i" , "empty unit j" , "empty unit k" , "empty unit l" , "empty unit m" , "empty unit n" , "empty unit o" , "empty unit p"},
                    {"empty unit a" , "empty unit b" , "empty unit c" , "empty unit d" , "empty unit e" , "empty unit f" , "empty unit g" , "empty unit h" , "empty unit i" , "empty unit j" , "empty unit k" , "empty unit l" , "empty unit m" , "empty unit n" , "empty unit o" , "empty unit p"},
                    {"empty unit a" , "empty unit b" , "empty unit c" , "empty unit d" , "empty unit e" , "empty unit f" , "empty unit g" , "empty unit h" , "empty unit i" , "empty unit j" , "empty unit k" , "empty unit l" , "empty unit m" , "empty unit n" , "empty unit o" , "empty unit p"},
                    {"empty unit a" , "empty unit b" , "empty unit c" , "empty unit d" , "empty unit e" , "empty unit f" , "empty unit g" , "empty unit h" , "empty unit i" , "empty unit j" , "empty unit k" , "empty unit l" , "empty unit m" , "empty unit n" , "empty unit o" , "empty unit p"},
                    {"empty unit a" , "empty unit b" , "empty unit c" , "empty unit d" , "empty unit e" , "empty unit f" , "empty unit g" , "empty unit h" , "empty unit i" , "empty unit j" , "empty unit k" , "empty unit l" , "empty unit m" , "empty unit n" , "empty unit o" , "empty unit p"},
                    {"empty unit a" , "empty unit b" , "empty unit c" , "empty unit d" , "empty unit e" , "empty unit f" , "empty unit g" , "empty unit h" , "empty unit i" , "empty unit j" , "empty unit k" , "empty unit l" , "empty unit m" , "empty unit n" , "empty unit o" , "empty unit p"},
                    {"empty unit a" , "empty unit b" , "empty unit c" , "empty unit d" , "empty unit e" , "empty unit f" , "empty unit g" , "empty unit h" , "empty unit i" , "empty unit j" , "empty unit k" , "empty unit l" , "empty unit m" , "empty unit n" , "empty unit o" , "empty unit p"},
                    {"empty unit a" , "empty unit b" , "empty unit c" , "empty unit d" , "empty unit e" , "empty unit f" , "empty unit g" , "empty unit h" , "empty unit i" , "empty unit j" , "empty unit k" , "empty unit l" , "empty unit m" , "empty unit n" , "empty unit o" , "empty unit p"},
                    {"empty unit a" , "empty unit b" , "empty unit c" , "empty unit d" , "empty unit e" , "empty unit f" , "empty unit g" , "empty unit h" , "empty unit i" , "empty unit j" , "empty unit k" , "empty unit l" , "empty unit m" , "empty unit n" , "empty unit o" , "empty unit p"},
                    {"empty unit a" , "empty unit b" , "empty unit c" , "empty unit d" , "empty unit e" , "empty unit f" , "empty unit g" , "empty unit h" , "empty unit i" , "empty unit j" , "empty unit k" , "empty unit l" , "empty unit m" , "empty unit n" , "empty unit o" , "empty unit p"}
};*/

    

    
void setup() {
    Serial.begin(115200);
    delay(20);
  
    Serial.println("   ");
    Serial.println("   ");
    Serial.println("   ");
    Serial.println("   ");
    Serial.println("   ");
    Serial.println("   ");
  
    for (int thisHouseCodeIndex = 0; thisHouseCodeIndex < 16; thisHouseCodeIndex++){
        for (int thisUnitCodeIndex = 0; thisUnitCodeIndex < 16; thisUnitCodeIndex++){
            Serial.print("HouseCode: ");
            //String myHouseCode = houseCodes[thisHouseCodeIndex];
            Serial.print(houseCodes[thisHouseCodeIndex]);
            //delay(20);
            Serial.print("   ");
          
            Serial.print("UnitCode: ");
         //   String myUnitCode = unitCodes[thisUnitCodeIndex];
            Serial.print(unitCodes[thisUnitCodeIndex]);
            //delay(20);
            Serial.print("   ");
          
            Serial.print("UnitID: ");
            String myUnitID = unitIDs[thisUnitCodeIndex][thisHouseCodeIndex];
            Serial.print(unitIDs[thisUnitCodeIndex][thisHouseCodeIndex]);
            //delay(20);
            Serial.print("   ");
          
            Serial.print("UnitName: ");
        //   String myUnitName = unitNames[thisUnitCodeIndex][thisHouseCodeIndex];
            //Serial.print(unitNames[thisUnitCodeIndex][thisHouseCodeIndex]);
            Serial.print(unitNames[thisHouseCodeIndex]);
            //delay(20);
            Serial.print("   ");
        
            Serial.println("   ");
            //delay(20);
        }
        Serial.println("   "); //---House Code: " + houseCode[i]+" ---");
        //delay(100);
    }
}

void loop() {
}
Live as if you were to die tomorrow. Learn as if you were to live forever. - Mahatma Gandhi

breagle

@MorganS,

houseCodes[], unitCodes[], unitIDs[] are constants. Those are the names. They are referring to X10 homeautomation addresses.

@DKWatson,

I was able to get the single [16] array to work as well. But then it causes errors when i try to use [16][16].

I don't understand if I am using the code incorrectly, or it is a hardware issue?

dougp

If by 'not printing correctly' you mean that some of the names don't print, I was able to duplicate that, albeit by cutting the arrays to [8] to  (barely) fit in my UNO.  I then removed a., the print statements for all but the unit names and b. the unitIDs array - whereupon the first seven unit names then print.  Further cutting the unitCodes array allows all unit names to print.

Maybe a print buffer issue?  Above my pay grade.  :)

The following prints all (modified, truncated) unit names on an UNO.  Uncommenting unitCodes[] only prints the first six.  Uncommenting unitIDs[][] causes no unit names to print.

Code: [Select]


String houseCodes[8] = {"A", "B", "C", "D", "E", "F", "G", "H"};

//String unitCodes[8] = {"1", "2", "3", "4", "5", "6", "7", "8"};
/*
  String unitIDs[8][8] = {
  {"A1", "B1", "C1", "D1", "E1", "F1", "G1", "H1"},
  {"A2", "B2", "C2", "D2", "E2", "F2", "G2", "H2"},
  {"A3", "B3", "C3", "D3", "E3", "F3", "G3", "H3"},
  {"A4", "B4", "C4", "D4", "E4", "F4", "G4", "H4"},
  {"A5", "B5", "C5", "D5", "E5", "F5", "G5", "H5"},
  {"A6", "B6", "C6", "D6", "E6", "F6", "G6", "H6"},
  {"A7", "B7", "C7", "D7", "E7", "F7", "G7", "H7"},
  {"A8", "B8", "C8", "D8", "E8", "F8", "G8", "H8"}
  };
*/
String unitNames[8][8] = {
  {"unit a0" , "unit b0" , "unit c0" , "unit d0" , "unit e0" , "unit f0" , "unit g0" , "unit h0"},
  {"unit a1" , "unit b1" , "unit c1" , "unit d1" , "unit e1" , "unit f1" , "unit g1" , "unit h1"},
  {"unit a2" , "unit b2" , "unit c2" , "unit d2" , "unit e2" , "unit f2" , "unit g2" , "unit h2"},
  {"unit a3" , "unit b3" , "unit c3" , "unit d3" , "unit e3" , "unit f3" , "unit g3" , "unit h3"},
  {"unit a4" , "unit b4" , "unit c4" , "unit d4" , "unit e4" , "unit f4" , "unit g4" , "unit h4"},
  {"unit a5" , "unit b5" , "unit c5" , "unit d5" , "unit e5" , "unit f5" , "unit g5" , "unit h5"},
  {"unit a6" , "unit b6" , "unit c6" , "unit d6" , "unit e6" , "unit f6" , "unit g6" , "unit h6"},
  {"unit a7" , "unit b7" , "unit c7" , "unit d7" , "unit e7" , "unit f7" , "unit g7" , "unit h7"}
};

void setup() {
  Serial.begin(230400);
  delay(20);

  Serial.println("   ");
  Serial.println("   ");
  Serial.println("   ");
  Serial.println("   ");
  Serial.println("   ");
  Serial.println("   ");

  for (int thisHouseCodeIndex = 0; thisHouseCodeIndex < 8; thisHouseCodeIndex++) {
    for (int thisUnitCodeIndex = 0; thisUnitCodeIndex < 8; thisUnitCodeIndex++) {
      /* Serial.print("HouseCode: ");
        //String myHouseCode = houseCodes[thisHouseCodeIndex];
        Serial.print(houseCodes[thisHouseCodeIndex]);
        //            delay(20);
        Serial.print("   ");

        Serial.print("UnitCode: ");
        //   String myUnitCode = unitCodes[thisUnitCodeIndex];
        Serial.print(unitCodes[thisUnitCodeIndex]);
        delay(20);
        Serial.print("   ");

        Serial.print("UnitID: ");
        String myUnitID = unitIDs[thisUnitCodeIndex][thisHouseCodeIndex];
        Serial.print(unitIDs[thisUnitCodeIndex][thisHouseCodeIndex]);
        //            delay(20);
        Serial.print("   ");
      */
      Serial.print("UnitName: ");
      //   String myUnitName = unitNames[thisUnitCodeIndex][thisHouseCodeIndex];
      Serial.print(unitNames[thisUnitCodeIndex][thisHouseCodeIndex]);
      //            delay(20);
      Serial.print("   ");

      Serial.println("   ");
      //            delay(20);
    } // end of unit code index
    Serial.println("   "); //---House Code: " + houseCode[i]+" ---");
    delay(20);
  } // end of house code index
}

void loop() {
}



So two neutrinos went into a bar.  Nothing happened.  They were just passing through.

MorganS

Code: (Just a Suggestion) [Select]
const int MaxUnits = 16;
const int MaxHouses = 16;
"The problem is in the code you didn't post."

DKWatson

I don't understand if I am using the code incorrectly, or it is a hardware issue?
The code as posted I ran on a mega with probably the same results as you got, about half of each didn't print the unitNames. So it's not a hardware problem and since it works with the single [16] array, that begins to narrow the problem down, yes?
Live as if you were to die tomorrow. Learn as if you were to live forever. - Mahatma Gandhi

DKWatson

Not figured it out yet?

Okay, one more clue. What's the word that starts with a capital 'S' that we all keep saying you should never use?

BTW, here's my output (truncated to fit),
Code: [Select]

  
HouseCode: A   UnitCode: 1   UnitID: A1   UnitName: empty unit a      
HouseCode: A   UnitCode: 2   UnitID: A2   UnitName: empty unit a      
HouseCode: A   UnitCode: 3   UnitID: A3   UnitName: empty unit a      
HouseCode: A   UnitCode: 4   UnitID: A4   UnitName: empty unit a      
HouseCode: A   UnitCode: 5   UnitID: A5   UnitName: empty unit a      
HouseCode: A   UnitCode: 6   UnitID: A6   UnitName: empty unit a      
HouseCode: A   UnitCode: 7   UnitID: A7   UnitName: empty unit a      
HouseCode: A   UnitCode: 8   UnitID: A8   UnitName: empty unit a      
HouseCode: A   UnitCode: 9   UnitID: A9   UnitName: empty unit a      
HouseCode: A   UnitCode: 10   UnitID: A10   UnitName: empty unit a      
HouseCode: A   UnitCode: 11   UnitID: A11   UnitName: empty unit a      
HouseCode: A   UnitCode: 12   UnitID: A12   UnitName: empty unit a      
HouseCode: A   UnitCode: 13   UnitID: A13   UnitName: empty unit a      
HouseCode: A   UnitCode: 14   UnitID: A14   UnitName: empty unit a      
HouseCode: A   UnitCode: 15   UnitID: A15   UnitName: empty unit a      
HouseCode: A   UnitCode: 16   UnitID: A16   UnitName: empty unit a      
  
HouseCode: B   UnitCode: 1   UnitID: B1   UnitName: empty unit b      
HouseCode: B   UnitCode: 2   UnitID: B2   UnitName: empty unit b      
HouseCode: B   UnitCode: 3   UnitID: B3   UnitName: empty unit b      
HouseCode: B   UnitCode: 4   UnitID: B4   UnitName: empty unit b      
HouseCode: B   UnitCode: 5   UnitID: B5   UnitName: empty unit b      
HouseCode: B   UnitCode: 6   UnitID: B6   UnitName: empty unit b      
HouseCode: B   UnitCode: 7   UnitID: B7   UnitName: empty unit b      
HouseCode: B   UnitCode: 8   UnitID: B8   UnitName: empty unit b      
HouseCode: B   UnitCode: 9   UnitID: B9   UnitName: empty unit b      
HouseCode: B   UnitCode: 10   UnitID: B10   UnitName: empty unit b      
HouseCode: B   UnitCode: 11   UnitID: B11   UnitName: empty unit b      
HouseCode: B   UnitCode: 12   UnitID: B12   UnitName: empty unit b      
HouseCode: B   UnitCode: 13   UnitID: B13   UnitName: empty unit b      
HouseCode: B   UnitCode: 14   UnitID: B14   UnitName: empty unit b      
HouseCode: B   UnitCode: 15   UnitID: B15   UnitName: empty unit b      
HouseCode: B   UnitCode: 16   UnitID: B16   UnitName: empty unit b      
  
HouseCode: C   UnitCode: 1   UnitID: C1   UnitName: empty unit c      
HouseCode: C   UnitCode: 2   UnitID: C2   UnitName: empty unit c      
HouseCode: C   UnitCode: 3   UnitID: C3   UnitName: empty unit c      
HouseCode: C   UnitCode: 4   UnitID: C4   UnitName: empty unit c      
HouseCode: C   UnitCode: 5   UnitID: C5   UnitName: empty unit c      
HouseCode: C   UnitCode: 6   UnitID: C6   UnitName: empty unit c      
HouseCode: C   UnitCode: 7   UnitID: C7   UnitName: empty unit c      
HouseCode: C   UnitCode: 8   UnitID: C8   UnitName: empty unit c      
HouseCode: C   UnitCode: 9   UnitID: C9   UnitName: empty unit c      
HouseCode: C   UnitCode: 10   UnitID: C10   UnitName: empty unit c      
HouseCode: C   UnitCode: 11   UnitID: C11   UnitName: empty unit c      
HouseCode: C   UnitCode: 12   UnitID: C12   UnitName: empty unit c      
HouseCode: C   UnitCode: 13   UnitID: C13   UnitName: empty unit c      
HouseCode: C   UnitCode: 14   UnitID: C14   UnitName: empty unit c      
HouseCode: C   UnitCode: 15   UnitID: C15   UnitName: empty unit c      
HouseCode: C   UnitCode: 16   UnitID: C16   UnitName: empty unit c      
  
HouseCode: D   UnitCode: 1   UnitID: D1   UnitName: empty unit d      
HouseCode: D   UnitCode: 2   UnitID: D2   UnitName: empty unit d      
HouseCode: D   UnitCode: 3   UnitID: D3   UnitName: empty unit d      
HouseCode: D   UnitCode: 4   UnitID: D4   UnitName: empty unit d      
HouseCode: D   UnitCode: 5   UnitID: D5   UnitName: empty unit d      
HouseCode: D   UnitCode: 6   UnitID: D6   UnitName: empty unit d      
HouseCode: D   UnitCode: 7   UnitID: D7   UnitName: empty unit d      
HouseCode: D   UnitCode: 8   UnitID: D8   UnitName: empty unit d      
HouseCode: D   UnitCode: 9   UnitID: D9   UnitName: empty unit d      
HouseCode: D   UnitCode: 10   UnitID: D10   UnitName: empty unit d      
HouseCode: D   UnitCode: 11   UnitID: D11   UnitName: empty unit d      
HouseCode: D   UnitCode: 12   UnitID: D12   UnitName: empty unit d      
HouseCode: D   UnitCode: 13   UnitID: D13   UnitName: empty unit d      
HouseCode: D   UnitCode: 14   UnitID: D14   UnitName: empty unit d      
HouseCode: D   UnitCode: 15   UnitID: D15   UnitName: empty unit d      
HouseCode: D   UnitCode: 16   UnitID: D16   UnitName: empty unit d      
  
HouseCode: E   UnitCode: 1   UnitID: E1   UnitName: empty unit e      
HouseCode: E   UnitCode: 2   UnitID: E2   UnitName: empty unit e      
HouseCode: E   UnitCode: 3   UnitID: E3   UnitName: empty unit e      
HouseCode: E   UnitCode: 4   UnitID: E4   UnitName: empty unit e      
HouseCode: E   UnitCode: 5   UnitID: E5   UnitName: empty unit e      
HouseCode: E   UnitCode: 6   UnitID: E6   UnitName: empty unit e      
HouseCode: E   UnitCode: 7   UnitID: E7   UnitName: empty unit e      
HouseCode: E   UnitCode: 8   UnitID: E8   UnitName: empty unit e      
HouseCode: E   UnitCode: 9   UnitID: E9   UnitName: empty unit e      
HouseCode: E   UnitCode: 10   UnitID: E10   UnitName: empty unit e      
HouseCode: E   UnitCode: 11   UnitID: E11   UnitName: empty unit e      
HouseCode: E   UnitCode: 12   UnitID: E12   UnitName: empty unit e      
HouseCode: E   UnitCode: 13   UnitID: E13   UnitName: empty unit e      
HouseCode: E   UnitCode: 14   UnitID: E14   UnitName: empty unit e      
HouseCode: E   UnitCode: 15   UnitID: E15   UnitName: empty unit e      
HouseCode: E   UnitCode: 16   UnitID: E16   UnitName: empty unit e      
  
HouseCode: F   UnitCode: 1   UnitID: F1   UnitName: empty unit f      
HouseCode: F   UnitCode: 2   UnitID: F2   UnitName: empty unit f      
HouseCode: F   UnitCode: 3   UnitID: F3   UnitName: empty unit f      
HouseCode: F   UnitCode: 4   UnitID: F4   UnitName: empty unit f      
HouseCode: F   UnitCode: 5   UnitID: F5   UnitName: empty unit f      
HouseCode: F   UnitCode: 6   UnitID: F6   UnitName: empty unit f      
HouseCode: F   UnitCode: 7   UnitID: F7   UnitName: empty unit f      
HouseCode: F   UnitCode: 8   UnitID: F8   UnitName: empty unit f      
HouseCode: F   UnitCode: 9   UnitID: F9   UnitName: empty unit f      
HouseCode: F   UnitCode: 10   UnitID: F10   UnitName: empty unit f      
HouseCode: F   UnitCode: 11   UnitID: F11   UnitName: empty unit f      
HouseCode: F   UnitCode: 12   UnitID: F12   UnitName: empty unit f      
HouseCode: F   UnitCode: 13   UnitID: F13   UnitName: empty unit f      
HouseCode: F   UnitCode: 14   UnitID: F14   UnitName: empty unit f      
HouseCode: F   UnitCode: 15   UnitID: F15   UnitName: empty unit f      
HouseCode: F   UnitCode: 16   UnitID: F16   UnitName: empty unit f      

Live as if you were to die tomorrow. Learn as if you were to live forever. - Mahatma Gandhi

breagle

Is there a different way without using String? At the bare minimum I need the UnitName[] as a String and the UnitID[] as a String. I think i should be able to locate the unit in the array from the index i use to cycle through the array. The UnitName is user created and the UnitID is constant. The ID give the house code and unit code of which unit to activate. I have seen a few X10 automation projects that only use 1 or 2 units. Some are able to use 16. The x10 is capable of using 256 devices all with an individual address using the house and unit code. I am using these String arrays to populate a webpage served by the arduino(showing: name and state: i.e. on, off, dim, bright). I am always running into memory or storage problems. I was able to get the system up and running a few years ago(with just 16 units), but always wanted the full 256.  Thanks again for any help.

DKWatson

There's a big difference between String and string. When we talk String we are talking about a class that will destroy memory on a MCU very quickly. Lower case string however, refers to c-string which is a character array. For the most part it behaves similarly although there are a complete different set of functions you would use to compare, copy, etc. The big difference is that it plays well with memory. You have four String arrays. Try changing String to char * and see what happens. Oh, also there is one more statement later on, String myUnitID = unitIDs[thisUnitCodeIndex][thisHouseCodeIndex]; that needs to be commented out.

One last point, stop printing spaces, they use up just as much memory. Learn how to print a tab if you want your output lined up.
Live as if you were to die tomorrow. Learn as if you were to live forever. - Mahatma Gandhi

DKWatson

#10
Nov 11, 2018, 07:36 am Last Edit: Nov 11, 2018, 07:40 am by DKWatson
One more last point, you can get rid of the delays, there is no buffer problem. Here is some nice clean code,
Code: [Select]
void setup()
{
    Serial.begin(115200);
   
    for (int thisHouseCodeIndex = 0; thisHouseCodeIndex < 16; thisHouseCodeIndex++)
    {
        for (int thisUnitCodeIndex = 0; thisUnitCodeIndex < 16; thisUnitCodeIndex++)
        {
            Serial.print("HouseCode: ");
            Serial.print(houseCodes[thisHouseCodeIndex]);
           
            Serial.print("\tUnitCode: ");
            Serial.print(unitCodes[thisUnitCodeIndex]);
           
            Serial.print("\tUnitID: ");
            Serial.print(unitIDs[thisUnitCodeIndex][thisHouseCodeIndex]);

            Serial.print(" \tUnitName: ");
            Serial.print(unitNames[thisUnitCodeIndex][thisHouseCodeIndex]);
            Serial.print("\n");
        }
        Serial.print("\n");
    }
}

And the first bit of output,
Code: [Select]
HouseCode: A UnitCode: 1 UnitID: A1 UnitName: empty unit a
HouseCode: A UnitCode: 2 UnitID: A2 UnitName: empty unit a
HouseCode: A UnitCode: 3 UnitID: A3 UnitName: empty unit w
HouseCode: A UnitCode: 4 UnitID: A4 UnitName: empty unit a
HouseCode: A UnitCode: 5 UnitID: A5 UnitName: empty unit a
HouseCode: A UnitCode: 6 UnitID: A6 UnitName: empty unit a
HouseCode: A UnitCode: 7 UnitID: A7 UnitName: empty unit a
HouseCode: A UnitCode: 8 UnitID: A8 UnitName: empty unit a
HouseCode: A UnitCode: 9 UnitID: A9 UnitName: empty unit a
HouseCode: A UnitCode: 10 UnitID: A10 UnitName: empty unit a
HouseCode: A UnitCode: 11 UnitID: A11 UnitName: empty unit a
HouseCode: A UnitCode: 12 UnitID: A12 UnitName: empty unit a
HouseCode: A UnitCode: 13 UnitID: A13 UnitName: empty unit a
HouseCode: A UnitCode: 14 UnitID: A14 UnitName: empty unit a
HouseCode: A UnitCode: 15 UnitID: A15 UnitName: empty unit a
HouseCode: A UnitCode: 16 UnitID: A16 UnitName: empty unit a

HouseCode: B UnitCode: 1 UnitID: B1 UnitName: empty unit x
HouseCode: B UnitCode: 2 UnitID: B2 UnitName: empty unit b
HouseCode: B UnitCode: 3 UnitID: B3 UnitName: empty unit b
HouseCode: B UnitCode: 4 UnitID: B4 UnitName: empty unit b
HouseCode: B UnitCode: 5 UnitID: B5 UnitName: empty unit b
HouseCode: B UnitCode: 6 UnitID: B6 UnitName: empty unit b
HouseCode: B UnitCode: 7 UnitID: B7 UnitName: empty unit b
HouseCode: B UnitCode: 8 UnitID: B8 UnitName: empty unit b
HouseCode: B UnitCode: 9 UnitID: B9 UnitName: empty unit b
HouseCode: B UnitCode: 10 UnitID: B10 UnitName: empty unit b
HouseCode: B UnitCode: 11 UnitID: B11 UnitName: empty unit b
HouseCode: B UnitCode: 12 UnitID: B12 UnitName: empty unit b
HouseCode: B UnitCode: 13 UnitID: B13 UnitName: empty unit b
HouseCode: B UnitCode: 14 UnitID: B14 UnitName: empty unit b
HouseCode: B UnitCode: 15 UnitID: B15 UnitName: empty unit b
HouseCode: B UnitCode: 16 UnitID: B16 UnitName: empty unit b
Live as if you were to die tomorrow. Learn as if you were to live forever. - Mahatma Gandhi

Go Up