我是编程Arduino的新手。在我的一个功能中,我收到了这个错误:
incompatible types in assignment of 'incompatible types in assignment
of 'byte (*)[13] {aka unsigned char (*)[13]}' to 'byte [15][13] {aka
unsigned char [15][13]}
matrix = board;
以下是代码:
byte matrix[][13] = { {247,199,199,199,199,193,0,7,199,199,199,199,223},
{ 241,0,0,0,0,0,0,0,0,0,0,0,31 },
{ 241,0,0,0,0,0,0,0,0,0,0,0,31 },
{ 241,0,0,0,0,0,0,0,0,0,0,0,31 },
{ 241,0,0,0,0,0,0,0,0,0,0,0,31 },
{ 241,0,0,0,0,0,0,0,0,0,0,0,31 },
{ 241,0,0,0,0,0,0,0,0,0,0,0,31 },
{ 245,68,68,68,68,68,68,68,68,68,68,68,95 },
{ 241,0,0,0,0,0,0,0,0,0,0,0,31 },
{ 241,0,0,0,0,0,0,0,0,0,0,0,31 },
{ 241,0,0,0,0,0,0,0,0,0,0,0,31 },
{ 241,0,0,0,0,0,0,0,0,0,0,0,31 },
{ 241,0,0,0,0,0,0,0,0,0,0,0,31 },
{ 241,0,0,0,0,0,0,0,0,0,0,0,31 },
{ 253,124,124,124,124,112,0,28,124,124,124,124,127 }};
byte BallX =7;
byte BallY=6;
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.print(findPossibleMoves(matrix,BallX,BallY,"",""));
while(1) {
}
}
String findPossibleMoves(byte board[][13], byte bx, byte by,String MyMove,String token) {
byte iterationCounter=0;
byte point = board[bx][by];
if((point==1)||(point==2)||(point==4)||(point==8)||(point==16)||(point==32)||(point==64)||(point==128)){
MyMove += token;
MyMove += "/";
return MyMove;
}
for(byte i=0;i<8;i++){
if(bitRead(point,i)) {
continue;
}
else{
if((token.length()>0) && (iterationCounter!=0)){
token.remove(token.length()-1);
}
iterationCounter++;
token+=String(i);
moveBall(matrix,i);
BallX = bx;
BallY = by;
matrix = board;
MyMove += findPossibleMoves(matrix,BallX,BallY,MyMove,token);
//MyMove+= "/";
//MyMove += token;
}
}
return MyMove;
}
void moveBall(byte board[][13],byte dir) {
byte point = board[BallX][BallY];
switch (dir)
{
case 0:
if (bitRead(point,0)==1)
{
break;
}
else {
board[BallX][BallY] |= 1;
BallX--;
board[BallX][BallY] |= 16;
}
break;
case 1:
if (bitRead(point,1)==1)
{
break;
}
else {
board[BallX][BallY] |= 2;
BallX--;
BallY++;
board[BallX][BallY] |= 32;
}
break;
case 2:
if (bitRead(point,2) == 1)
{
break;
}
else {
board[BallX][BallY] |= 4;
BallY++;
board[BallX][BallY] |= 64;
}
break;
case 3:
if (bitRead(point,3) == 1)
{
break;
}
else {
board[BallX][BallY] |= 8;
BallX++;
BallY++;
board[BallX][BallY] |= 128;
}
break;
case 4:
if (bitRead(point,4) == 1)
{
break;
}
else {
board[BallX][BallY] |= 16;
BallX++;
board[BallX][BallY] |= 1;
}
break;
case 5:
if (bitRead(point,5) == 1)
{
break;
}
else {
board[BallX][BallY] |= 32;
BallX++;
BallY--;
board[BallX][BallY] |= 2;
}
break;
case 6:
if (bitRead(point,6) == 1)
{
break;
}
else {
board[BallX][BallY] |= 64;
BallY--;
board[BallX][BallY] |= 4;
}
break;
case 7:
if (bitRead(point,7) == 1)
{
break;
}
else {
board[BallX][BallY] |= 128;
BallX--;
BallY--;
board[BallX][BallY] |= 8;
}
break;
default:
break;
}
}
我真的不知道造成这个错误的原因。我浏览网页,我唯一能找到的就是从matrix
声明中删除第一个维度的大小。你们可以帮我解决一下如何解决这个问题吗?
答案 0 :(得分:1)
您不能像以下那样一次将整个数组分配给另一个数组:
matrix = board;
您需要逐个复制元素或使用memcpy之类的函数来复制内存块。