gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-27 23:55:17 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com