监视按钮是否已停止按下
我有一个 Arduino 草图,当按下板上的按钮时,它会通过串行端口报告数据。读取串行端口的是 Node.js 服务器,当按下按钮时,它与操作系统进行一些交互。
我首先发现的问题是,如果我不在循环末尾添加延迟,Node.js 服务器似乎会出现瓶颈,并在完成最后一组指令之前开始读取下一组指令。每个循环总是将数据发送到串行端口。
无论如何,我将草图设置为在每个循环结束时延迟 100 毫秒。
我现在发现的问题是,如果我按住按钮超过 100 毫秒,它会将其视为按下了 2 次按钮,因此每次按下按钮时运行的 Node.js 代码都会加倍。有没有办法可以判断按下按钮的用户是否已松开按钮?
I have an Arduino sketch that reports data over the serial port when a button is pressed on the board. What is reading the serial port is a Node.js server that has some interactions with the OS when the button is pressed.
The problem that I found first was that if I didn't put a delay at the end of my loop was that the Node.js server would seem to bottleneck and start reading the next set of instructions before finishing the last set. Each loop always sends data over to the serial port.
Anyways I set my sketch to delay for 100 milliseconds at the end of each loop.
The problem that I found now is that if I hold the button down for more than that 100ms it sees it as 2 button presses and so the node.js code that runs on each button press gets doubled up. Is there a way that I can tell if the user pressing the button has released the press?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要添加一个软件来对开关进行去抖处理。
根据您的应用程序可能需要自动重复或发送不同的
释放开关时的代码。
如果您只想发送一封,您可以添加如下代码:
You need to add a software to debounce the switch.
Depending on your app to might want an autorepeat or send a different
code when the switch is released.
If you only want one sent, you can add code like below: