检查除法是否给出余数 0
checking if a division gives remainder 0
嗨,我
正在编写一个 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 毫秒数。您应该划分秒数。
相关文章:
- 在除法中不需要四舍五入
- 在TFHE(完全快速同态加密)上执行除法
- 使用 int 表示浮点除法 C++
- 而循环:简单的除法程序输出零,不明白为什么
- 余数除法和不允许除以零 (c++) 时遇到问题
- 余数运算符的等效操作,用于处理低于允许的最小值
- 如何确定涉及 C++ 中除法的算术表达式的数据类型
- 如何使用除法和for_each?
- C++:奇怪的除法输出
- 分配给浮点数的积分文字除法 - 为什么结果是错误的?
- 除法函数返回错误的值
- 检查向量是否使用除法和阻抗算法进行排序
- 如何找到给定范围内除以给定数字时具有一定余数的值的数量?
- 计算浮点余数的最佳方法
- 不使用算术运算符的除法
- 除法函数随机整数需要打印出商和余数
- 检查除法是否给出余数 0
- 为什么在C和C++中没有浮点/双精度的除法余数运算
- 除法的商数和余数大整数与一个大整数的乘积
- 最好的方法来获得整数除法和余数