问题出在数组上。声明数组的那一行没有问题,就是它后面的那些。看来我不能像在 C 中那样编码。 为了清楚起见,我该如何修复它,因为我需要这种格式。我不想写很长的一行,因为这个数组中有 15 个变量。
这是代码
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
#define SERVOMIN 150 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX 600 // this is the 'maximum' pulse length count (out of 4096)
///// void setup /////
void setup() {
Serial.begin(9600);
pwm.begin();
pwm.setPWMFreq(60); // Analog servos run at ~60 Hz updates
delay(10);
}
///// Coordonnees /////
int angles[5][3]; //angles de chaque moteur pour chaque cube
angles[0][0]=60;
angles[0][1]=120;
angles[0][2]=100;
基本上是 angles[0][0]=;
和与其类似的线导致了问题。
最佳答案
在全局范围内只有少数事情是允许的,赋值不是其中之一。
您可以声明或定义变量(并初始化它们),所以这就是您可以定义数组的原因。实现目标的一种方法是初始化数组,而不是为其赋值:
int angles[5][3] {
{1, 2, 3},
{3, 4, 5},
{5, 6, 7},
{8, 9, 10},
{11, 12, 13}
};
关于c++ - Arduino 数组没有命名类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50747457/