2017-04-30 15 views
-2

このプログラムは、電気モータを制御して、120ボルトを出力する前に3秒、255ボルトを出力するのに3秒後に調整します。なぜこれがコンパイルされないのか分かりません。arduinoコードで何が間違っていますか?私はエラーをコンパイルするのに失敗した理由をよく知りません

int motorPin = 9; 

void setup() { 
    // put your setup code here, to run once: 
    pinMode(9,OUTPUT); 
} 

void loop() { 
    // put your main code here, to run repeatedly: 
    #include <time.h> 

    if (int tm_sec<int tm_3sec); 
    analogWrite(9,120); 

    else (int tm_sec>int tm_3sec); 
    analogWrite(9,255); 
+0

'include()'ステートメントを 'loop()'関数から移動する必要があります。 'if'の後にセミコロンも削除してください。同様に、 'tm_sec'を宣言してください....多くの問題があります。 –

+0

#includeはloop()内の適切な場所にありません。 – JimmyB

+2

コンパイラの出力を実際に含めてください –

答えて

0

多くの問題があります。まず、includeディレクティブは、そのコード行をファイル全体に置き換え、通常はソースコードファイルの先頭に配置します。さらに、これはArduinoです。代わりにmillis()を使用してください。

const int motorPin = 9; 

void setup() { 
    pinMode(motorPin, OUTPUT); 
} 

void loop() { 
    // millis() resets to 0 when the Arduino resets 
    if (millis() < 3000) { 
     analogWrite(motorPin, 120); 
    } 
    else { 
     analogWrite(motorPin, 255); 
    } 
} 

ただし、120Vと255Vは出力されません。 Arduinoはそれをすることはできません。 analogWriteは、送信する値に基づいてPWM信号を書き込みます。 https://www.arduino.cc/en/Reference/analogWrite

関連する問題