为什么这个Arduino代码不起作用?

时间:2016-03-13 19:54:29

标签: arduino

为什么这段代码不起作用? 我正在http://www.codebender.cc上运行这个Arduino代码,它不会在我的Arduino Uno上运行。当我在串行监视器上运行时没有打印出来,我完全不知道为什么? 看看......

const int button1 = 8;
const int button2 = 9;
const int button3 = 10;

int ison1 = 0;
int ison2 = 0;
int ison3 = 0;

int x = 1;
int y = 1;
int z = 1;

void setup()
{
    pinMode(button1, INPUT);
    pinMode(button2, INPUT);
    pinMode(button3, INPUT);
}

void go()
{
    Serial.print("Press button 1 (Furthest to the right)...");
    while (x == 1){
        ison1 = digitalRead(button1);
        if (ison1 == HIGH){
            Serial.print("Well done!");
            x = 2;
        }
    }
    Serial.print("Press button 2 (The middle one)...");
    while (y == 1){
        ison2 = digitalRead(button2);
        if (ison2 == HIGH){
            Serial.print("Well done!");
            y = 2;
        }
    }
    Serial.print("Press button 3 (Furthest to the left)...");
    while (z == 1){
        ison3 = digitalRead(button3);
        if (ison3 == HIGH){
            Serial.print("Well done!");
            z = 2;
        }
    }
    Serial.print("You have completed the test!");
}


void loop()
{
    delay(5000);
    go();
    exit(0);
}

1 个答案:

答案 0 :(得分:1)

将此添加到setup

Serial.begin( 9600 );

我已多次这样做了...... :)