不要等待arduino回复
我正在使用 Arduino 和一把真正的吉他来创建一款吉他英雄类游戏。
我的问题是我必须不断检查 arduino 的返回值。
如果我不断地发送一个值,我的读数就不再足够准确,并且如果我以这样的方式为 Arduino 编写代码,使其仅在接收到来自我的吉他的输入时发送数据,则 Unity 程序会由于它变得越来越冻结而冻结卡在 Arduino 代码上,因为它似乎一直在等待响应。有什么办法可以解决这个问题吗?
I'm creating a guitar hero kind of game in unity using an Arduino and an actual guitar.
My problem is that I have to constantly check for a returning value from the arduino.
If I constantly send a value my readings aren't accurate enough any more, and if I write my code for the Arduino in such a way that it only sends data when it receives input from my guitar, the unity program freezes due to it getting stuck on the Arduino code as it seems to keep waiting for a response. Is there a way that I can work around this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我理解你的基本问题是:
答:有两种方法可以做到这一点:
轮询
事件
轮询是不好的:)
正确的方法是使用事件,如果可能的话。
假设您可以使用 C# 串行接口,那么您可以将一个事件分配给 DataReceived。
这是一篇文章,准确讨论了这一点:
http: //www.johnciacia.com/2010/06/03/interacting-with-the-arduino-with-c/
查找:
这是另一个链接:它看起来像“Scrobby4”发布了一些示例代码:
http://forum.unity3d.com/threads /14731-COM1-和事件
I understand your basic question to be:
A: There are two ways you can do it:
Polling
Events
Polling is Bad :)
The correct way is to use an event, if at all possible.
Assuming you can use the C# serial interface, then you can assign an event to DataReceived.
Here's an article that discusses precisely that:
http://www.johnciacia.com/2010/06/03/interacting-with-the-arduino-with-c/
Look for:
Here's another link: it looks like "Scrobby4" posted some example code:
http://forum.unity3d.com/threads/14731-COM1-and-events