首页 文章

'Serial'之前';'(Arduino IDE 1.8.7)[暂停]

提问于
浏览
-4

我的代码会使内部LED以1 Hz的频率闪烁,但前提是光电二极管(引脚4)被拉至高电平(光电二极管为INPUT_PULLUP) .

这是我使用的代码:

void setup (){
    // sets pin 13 (LED) as a output
    pinMode (13, OUTPUT);
    // sets pin 4 (photodiode) as input (pull_up)
    pinMode (4, INPUT_PULLUP)
    // starts the serial monitor at 9600 baud
    Serial.begin (9600);
}

void loop () {
    if (pin4 == HIGH) {
        // prints "Your LED is ready. If the LED blinks, it works properly.
        Serial.println("The photodiode has been pulled to a on state.");
        // blinks the LED with a 1 hz square wave
        digitalWrite (13, HIGH);
        delay (1000);
        digitalWrite (13, LOW);
        delay (1000);
    }
    else {
        digitalWrite (13, LOW)
    }
}

坏线是

Serial.begin (9600);

1 回答

  • 0

    有一些 ; 缺失:

    void setup (){
        // sets pin 13 (LED) as a output
        pinMode (13, OUTPUT);
        // sets pin 4 (photodiode) as input (pull_up)
        pinMode (4, INPUT_PULLUP);     // Here a ; is missing
        // starts the serial monitor at 9600 baud
        Serial.begin (9600);
    }
    
    void loop () {
        if (pin4 == HIGH) {
            // prints "Your LED is ready. If the LED blinks, it works properly.
            Serial.println("The photodiode has been pulled to a on state.");
            // blinks the LED with a 1 hz square wave
            digitalWrite (13, HIGH);
            delay (1000);
            digitalWrite (13, LOW);
            delay (1000);
        }
        else {
            digitalWrite (13, LOW);    // and here another one
        }
    }
    

相关问题