检查模拟值是否在阈值内
我正在从 µC 上的引脚读取模拟值。 我想定期检查该值的变化是否超过 x
。 在这里,我使用 abs()
函数,但我想保持简单。 你能帮助我吗?
int algVal= 0;
int oldVal = 0
while(1){
algVal = getAlgVal();
if(abs(algVal - oldVal) > x)
{
doStuff();
}
oldVal= algVal:
}
I'm reading an analogue value from a Pin on a µC.
I want to check periodically if the value has changed more than x
.
Here, I am using the abs()
function, but I want to keep it simple.
Can you help me?
int algVal= 0;
int oldVal = 0
while(1){
algVal = getAlgVal();
if(abs(algVal - oldVal) > x)
{
doStuff();
}
oldVal= algVal:
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这听起来是一个很棒的方法,并且在运行时性能方面可能会非常好,整数的
abs()
很便宜。如果有疑问,当然请阅读生成的程序集。That sounds like a fantastic approach, and would probably be very nice in terms of runtime performance,
abs()
for integers is cheap. If in doubt, read the generated assembly of course.