检查除法是否给出余数 0

checking if a division gives remainder 0

本文关键字:余数 除法 是否 检查      更新时间:2023-10-16
嗨,我

正在编写一个 Arduino 程序,我必须检查除以 60 的变量是否得到余数 0。此变量每秒增加 1。我试着写

if (variable % 60 == 0){
...
}

但即使变量为 3、6、9,它也能工作......

我的确切代码是:

    if (millis()/1000 != prevsec){
    prevsec = millis()/1000;
    if (millis() % 60 == 0){
      Serial.print("light");
  Serial.println(analogRead(0));
  tempC = analogRead(1);           //read the value from the sensor
  tempC = (5.0 * tempC * 100.0)/1024.0;  //convert the analog data to temperature
  Serial.print("tempin");
  Serial.println((byte)tempC); 
    }
    Serial.println(millis()/1000);
  }

请告诉我我做错了什么提前感谢!

看起来好像你除以 60 毫秒数。您应该划分秒数。