目前我正在研究我的4x4x4 LED立方体,我想为它编写自己的代码,但目前我被卡在使用3D阵列上。我在void setup()中声明了几个数组,并且我也尝试将它们放入void loop()中。尽管如此,当试图编译时,它仍然会返回错误。Arduino的3D阵列
简而言之,代码应该生成一个带有XYZ值的随机点。然后它必须将其写入缓冲区,此缓冲区必须将其投影并多路传输到LED立方体上。
我做了返回错误粗体的行。
的错误是:
LedCube1.0.ino: In function 'void loop()':
LedCube1.0.ino:41:3: error: 'ledBuffer' was not declared in this scope
LedCube1.0.ino:41:13: error: 'xSeed' was not declared in this scope
LedCube1.0.ino:41:20: error: 'ySeed' was not declared in this scope
LedCube1.0.ino:41:27: error: 'zSeed' was not declared in this scope
LedCube1.0.ino:42:7: error: 'rainstep' was not declared in this scope
LedCube1.0.ino: In function 'int allOff()':
LedCube1.0.ino:76:9: error: 'ledBuffer' was not declared in this scope
LedCube1.0.ino: In function 'int allOn()':
LedCube1.0.ino:86:9: error: 'ledBuffer' was not declared in this scope
Error compiling.
代码:
void setup() {
//sets all pins as output
for(int a=22;a<53;a++){
pinMode(a, OUTPUT);
}
//declares the sizes of the cube
int width = 4;
int depth = 4;
int height = 4;
int ledBuffer[4][4][4] = { //creates a buffer that can store values generated by a function
{
{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}, {0,0,0,0}, {0,0,0,0},
}
};
//defines to which connector each layer is connected
int ledXY[4][4] = {
{22,24,26,28} ,
{30,32,34,36},
{23,25,27,29},
{31,33,35,37}
};
int ledZ[4] = {38,40,42,44};
//create variables to start generating raindrops
int rainstep = 0;
int xSeed = 0;
int ySeed = 0;
int zSeed = 0;
}
void loop() {
//generatedrop
ledBuffer[xSeed][ySeed][zSeed] = 0;
if (rainstep == 0)
{
int xSeed=random(0,3);
int ySeed=random(0,3);
int zSeed=random(0,3);
}
else
{
zSeed = zSeed - rainstep;
}
ledBuffer[xSeed][ySeed][zSeed] = 1;
//updatecube
for(int i=0; i<80;i++){
int currentZ = i%4;
allOff;
for(int j=0;j<4;j++){
for(int k=0; i<4;i++){
if(ledBuffer[i][j][k]==0){
digitalWrite(ledBuffer[i][j][k],HIGH);
}else{
digitalWrite(ledBuffer[i][j][k],LOW);
}
}
}
}
}
//function declares entire array 0
int allOff(){
for(int c=0;c<4;c++){
for(int d=0;d<4;d++){
for(int e=0;e<4;e++){
ledBuffer[c][d][e]=0;
}
}
}
};
//function declares entire array 1
int allOn(){
for(int c=0;c<4;c++){
for(int d=0;d<4;d++){
for(int e=0;e<4;e++){
ledBuffer[c][d][e]=1;
}
}
}
};
I re
有人可以帮助我,或至少点我在正确的方向。
在测试任何代码之前,不应该编写这么多的代码。你试图至少得到两件新事物同时工作;独立开发它们,然后将它们挂在一起。 – Beta