c++ - Arduino 数组没有命名类型

标签 c++ arrays types arduino arduino-uno

问题出在数组上。声明数组的那一行没有问题,就是它后面的那些。看来我不能像在 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/

相关文章:

c++ - Qt 警告:传递 qreal 进行转换 QRect::QRect(int, int, int, int)

c++ - std::filesystem::path 在没有临时 std::string 转换的情况下获取给定基本路径的相对路径?

javascript - 使用 .map 对数组中的所有数字进行因式分解

java - 如何在数组中添加 40 以下的数字

c - 在 c 中使用 Merge Sort 进行排序时保留原始索引

c# - 如何将对象转换为 Type 类描述的类型?

c++ - 如何使这些类对单元测试更友好?

c++ - 在类模板中正确初始化静态 constexpr 数组?

c# - vb/c#十进制内部格式

c# - 从通用类型问题推断