im working on a school project and a boolean 2d array we are using is either not changing the spot in the array that we want to or its changing more then that cell, also the last number in the array is a random value between 0 and 255 even if its a bool
bool horWalls[7][8] =
{
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0}
};
byte cell[2];
void setup() {
Serial.begin(9600);
horWalls[ cell[1] + 2 ] [ cell[0] ] = 1;
Serial.println("placehorwall");
}
void loop() {
for (int y = 0; y != 7 ; y++) {
for (int x = 0; x != 7 ; x++) {
Serial.print(horWalls[y][x]);
Serial.print(" ");
}
Serial.println(horWalls[y][8]);
}
Serial.println("");
}
results in
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 117 and the 117 changing even though its only serial prints
in a larger program neither of the 1's appear
this happens in a physical due and an online simulated mega in wokwi.com
is there a way to fix this?