0

私はここにいくつかのコードを持っています、私は前のifのないelseがあると言います、事はifがあるということです。また、ここでモジュロを使用するにはどうすればよいですか、無効な二項演算子と言いますか???

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  Serial.begin(9600);
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
}

void loop() {
  delay(500);
  int sensorval = analogRead(A0);
  float outval = (sensorval/1024.0) * 5.0;
  float cel =(outval - .5) * 100;
  float far = (cel*1.8000000)+32;
  lcd.setCursor(0,0);
  lcd.print("Farien ");
  lcd.print(far,6);

  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  double secs = (millis()/1000);

  if(secs <= 60.0);
  {
      lcd.print(millis()/1000);
  }
  else
  {
    double hrs = (millis()/1000) / 3600.0;
    double mins = hrs / 60.0;
    double secs = mins % 60;
  }
}

これは十分に簡単に思えますが、私は初心者であり、大きな助けが必要です

4

1 に答える 1

1

あなたのifコード

  if(secs <= 60.0);

ステートメントを終了する冗長なセミコロンがあります。したがって、次のブロックは無条件ブロックであるため、else ステートメントはエラーにつながります。

モジュロ演算に関して: コンパイラは「無効な演算子」とは言いません。「二項演算子 % への型 'double' および 'int' の無効なオペランド」と記載されています。これは、このために double と int を混ぜてはならないことを意味します。double から離れて完全に整数 (uint32_t など) に移行することをお勧めします。

于 2013-10-12T06:17:01.390 に答える