/* 27/08/2021 * * arrayv5 * * Errors and dangers from over running the end of the array * * Examples of what NOT TO DO * * Full video tutorial at www.digitaltown.co.uk * * No pins used * */ //Create an integer array and populate it with values. int carPark[6] = {1,2,3,4,5,6}; int carParkSlotCounter = 0; int mainCounter; void setup() { int q; Serial.begin(9600);//Start Serial at 9600 Serial.println("arrayv5...");//File name Serial.println(" ");//Blank line //Array has 6 elements, in this loop we jump through 10 values Serial.println("Over running the end of the array"); for(carParkSlotCounter = 0;carParkSlotCounter< 10;carParkSlotCounter++){ Serial.println(carPark[carParkSlotCounter]); } } void loop() { //Uncomment the block below to see what happens when you change values outside the array boundary //This will not damage your Arduino but will probably cause a weird output to serial monitor //This is done as an example of what NOT TO DO /* Serial.println("Change the values in the array...exceeding array limits"); for(carParkSlotCounter = 0;carParkSlotCounter< 10;carParkSlotCounter++){ //This line changes the values in the array carPark[carParkSlotCounter] = mainCounter; mainCounter++; //Print out the new value Serial.println(carPark[carParkSlotCounter]); } delay(2000); Serial.println("Add 100 to the values in the array exceeding array limits"); for(carParkSlotCounter = 0;carParkSlotCounter< 10;carParkSlotCounter++){ //This line increases the value in the array by 100 carPark[carParkSlotCounter] = carPark[carParkSlotCounter] + 100; //print out the new value Serial.println(carPark[carParkSlotCounter]); } delay(2000); */ }