Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在从微控制器上的引脚读取模拟值。我想定期检查值是否变化超过x. 在这里,我正在使用该abs()功能,但我想保持简单。你能帮助我吗?
x
abs()
int algVal= 0; int oldVal = 0 while(1){ algVal = getAlgVal(); if(abs(algVal - oldVal) > x) { doStuff(); } oldVal= algVal: }
这听起来像是一种绝妙的方法,并且在运行时性能方面可能会非常好,abs()因为整数很便宜。如果有疑问,当然要阅读生成的程序集。