我收到一个奇怪的编译错误(arduino)

时间:2015-02-02 19:21:24

标签: c++ arduino

以下是错误:

  

core.a(main.cpp.o):在函数' main':   
C:\ Program Files(x86)\ Arduino \ hardware \ arduino \ cores \ arduino / main.cpp:11:>
未定义参考'设置'
  C:\ Program Files(x86)\ Arduino \ hardware \ arduino \ cores \ arduino / main.cpp:14:>
未定义引用'循环'

我似乎无法弄明白。 这是代码。

void setup(int x, int y) //make joystick arcade style controller
{
int powY;
int powX;
int powRightMotor;
int powLeftMotor;
int powmotordriveright;
int powmotordriveleft;

// convert joystick -128 to 127 range to -100 to 100 for powering motors
powY = (y * 100) / 127; //joystick y axis gives maximum power level
powX = (x * 100) / 127; //x axis determines which motor is reduced or
//reversed for a turn

for
if (powX < 0) //if x negative, turning left; otherwise, turning right
{
powLeftMotor = (powY * (100 + (2 * powX))/100); //left motor reduced for right turn
powRightMotor = (powY * -(100 + (2 * powX))/100); //right motor is reversed
}
else
{
powRightMotor = (powY * (100 - (2 * powX))/100); //right motor reduced for left turn
powLeftMotor = (powY * -(100 + (2 * powX))/100); //left motor reversed
}

powRightMotor = powmotordriveright;
powLeftMotor = powmotordriveleft;
}
loop;

1 个答案:

答案 0 :(得分:4)

你真的需要从头开始。首先学习闪烁程序,以便了解Arduino的工作原理并与您提供的代码进行交互。

以此图片为例

Arduino Blink

创建setup()方法(不带参数)并设置所需的所有引脚,然后创建一个loop()方法,该方法将循环并从引脚输入并输出到一组引脚间隔。

请查看此答案中的链接,我认为您会发现它们很有帮助。


你应该有这样的东西

void setup() //make joystick arcade style controller
{
    //Joystick input you may need more depending on the 
    //device that you are using
    pinMode(13, INPUT);
    pinMode(14, INPUT); 
    //output pins to the motors
    pinMode(11, OUTPUT);
    pinMode(12, OUTPUT);
    //

}

void loop()
{
    int powY;
    int powX;
    int y = analogRead(13); // you could also set your pins to variables
    int x = analogRead(14); // and probably should for readability

    int powRightMotor;
    int powLeftMotor;
    int powmotordriveright;
    int powmotordriveleft;

    // convert joystick -128 to 127 range to -100 to 100 for powering motors
    powY = (y * 100) / 127; //joystick y axis gives maximum power level
    powX = (x * 100) / 127; //x axis determines which motor is reduced or
    //reversed for a turn


    if (powX < 0) //if x negative, turning left; otherwise, turning right
    {
        powLeftMotor = (powY * (100 + (2 * powX))/100); //left motor reduced for right turn
        powRightMotor = (powY * -(100 + (2 * powX))/100); //right motor is reversed
    }
    else
    {
        powRightMotor = (powY * (100 - (2 * powX))/100); //right motor reduced for left turn
        powLeftMotor = (powY * -(100 + (2 * powX))/100); //left motor reversed
    }

    powRightMotor = powmotordriveright;
    powLeftMotor = powmotordriveleft;

    //you are going to want to transform the value to something between 0-255 for an analogWrite
    //it's been a while since I worked with arduinos and wrote the actual code, and I don't know
    //what you are working with either.

    analogWrite(11, powRightMotor);
    analogWrite(12, powLeftMotor
}

在这种情况下,我们不需要for循环,因为loop()方法已经执行此操作&#34;开箱即用&#34;。所以我们只检查所有输入并转换值以运行电机。

我可能已经屠杀了这个,因为我不知道你正在进行什么样的硬件设置,但我很确定这应该编译

要在Arduino平台上运行,你绝对需要这两种方法,Arduinos很挑剔。


如果您需要使用for循环设置无限循环,它将像这样构建

for (;;)
{
    //do work here
}   

使loop;无法执行任何操作,这是语法错误。

(参考Arduino.cc以获得适当的循环结构)

虽然while循环对于无限循环可能更好,但是你可以设置一个布尔值,并在某些情况下让它退出。有一个不可避免的循环不是一个好主意。