/* 27/08/2021 arrayv3 Understand how to set up, read from, write to and edit a 3 dimensional array Full video tutorial at www.digitaltown.co.uk No pins used */ //Create a 3 dimension integer array. //[3] is the floors,[4] is the number of rows, [6] number of slots per row int carPark[3][4][6]; int carParkSlotCounter = 0; int carParkRowCounter = 0; int carParkFloorCounter = 0; int mainCounter; void setup() { Serial.begin(9600);//Start Serial at 9600 Serial.println("arrayv3...");//File name Serial.println(" ");//Blank line } void loop() { Serial.println("Set the values in the array"); for (carParkFloorCounter = 0; carParkFloorCounter < 3; carParkFloorCounter++) { for (carParkRowCounter = 0; carParkRowCounter < 4; carParkRowCounter++) { for (carParkSlotCounter = 0; carParkSlotCounter < 6; carParkSlotCounter++) { //This line changes the values in the array carPark[carParkFloorCounter][carParkRowCounter][carParkSlotCounter] = mainCounter; mainCounter++; //Print out the new values seperated by a comma Serial.print(carPark[carParkFloorCounter][carParkRowCounter][carParkSlotCounter]); Serial.print(","); } //End of row so end line Serial.println(" "); } Serial.print("End of Floor: "); Serial.println(carParkFloorCounter); } delay(2000); //Print out an individual value, 1st floor, 2nd row, 4th item Serial.println("Print out an individual value, floor 1 2nd row, 4th item"); Serial.println(carPark[0][1][3]);//1st floor [0] start from ZERO, 2nd row is [1] start from ZER0, 4th item therfore is [3] delay(2000); //Print out an individual value, floor 1 2nd row, 4th item item after adding 100 carPark[0][1][3] += 100; Serial.println("Print out an individual value, 2nd row, 4th item after adding 100"); Serial.println(carPark[0][1][3]);//2nd row is [1] start from ZER0, 4th item therfore is [3] delay(2000); Serial.println("Add 1000 to the values in the array"); for (carParkFloorCounter = 0; carParkFloorCounter < 3; carParkFloorCounter++) { for (carParkRowCounter = 0; carParkRowCounter < 4; carParkRowCounter++) { for (carParkSlotCounter = 0; carParkSlotCounter < 6; carParkSlotCounter++) { //This line changes the values in the array carPark[carParkFloorCounter][carParkRowCounter][carParkSlotCounter] = carPark[carParkRowCounter][carParkSlotCounter] + 1000; //The line above can be written carPark[carParkFloorCounter][carParkRowCounter][carParkSlotCounter] += 1000; //Print out the new values seperated by a comma Serial.print(carPark[carParkFloorCounter][carParkRowCounter][carParkSlotCounter]); Serial.print(","); } //End of row so end line Serial.println(" "); } Serial.print("End of Floor: "); Serial.println(carParkFloorCounter); } delay(2000); }