c - Arduino : "error: expected unqualified-id before ' {' token"

标签 c arduino-uno

当我尝试编译此代码时,我在标题中收到错误消息。我对此很陌生,不确定是否有什么事情完全超出了我的理解范围。这段代码只是为了测试我试图用 arduino 实现自动驾驶的遥控汽车上的接线。我之前曾在这里作为问题看到过此错误消息,但我找不到将那里的解决方案应用到我的代码的方法。我尝试查看所有括号并确保它们彼此配对(例如 {},而不是 {{ 或 }} 或 }{)。我希望能够在感恩节假期之前解决这个问题,因此非常感谢任何帮助。

int driveneg = 9;
int drivepos = 5;   /*this shows all my variables*/
int steeringneg = 6;
int steeringpos = 3;

byte speed =255;

    void setup ();
    {
        pinMode (steeringneg, OUTPUT); 
        pinMode (steeringpos, OUTPUT); /*setting the motors to output*/
        pinMode (driveneg, OUTPUT);
        pinMode (drivepos, OUTPUT);
    }
    void loop ();
    {
        forward();
        delay (2000);
        backward();
        delay (2000);
    }
    void backward();
    {
        analogWrite (9,0);
        analogWrite (5, speed);/*defines forward and backward functions*/
        analogWrite (6, 0);
        analogWrite (3, speed);
    }
    void forward();
    {
        analogWrite (9, speed);
        analogWrite (5, 0);
        analogWrite (6, speed);
        analogWrite (3, 0);
    }

最佳答案

删除函数括号后面的分号 (;),如下所示:

void setup ()
{
    ...
}

关于c - Arduino : "error: expected unqualified-id before ' {' token",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40707343/

相关文章:

C# SerialPort GetPortNames 在 Windows 10 上不起作用

arduino-uno - AT+CSQ?返回错误

c - Haskell FFI 关于双指针参数的问题

c - void 的奇怪用法

c - 使用 "NA"将 R 数组传递给 C 函数

arduino - 向 ESP8266 发送 AT+CWJAP_DEF 命令时出错

c++ - Arduino 中的 Serial.print uint64_t

c - 当我们将值存储在 scanf 中的变量中时,c 编译器如何找到该值的地址?

c++ - 'TraceEvents' 未定义;假设 extern 返回 int

c - 这行简单的 C 代码如何工作?