我如何将信号发送到计算机

发布于 2025-02-03 20:17:35 字数 250 浏览 4 评论 0原文

对你们每个人的问候。我需要你的帮助。我正在从事一个项目。当A&gt时,我需要大于5,Arduino向计算机发送信号,并开始在计算机上播放视频。我的计算机操作系统是Windows111。我想在Windows Media Player或其他任何内容上播放视频。每次我的计算机都开放,并且在媒体播放器上进行视频准备就绪。我不知道该怎么做。首先,我连接了伺服电机,伺服电机旋转了70度,并击中了计算机的“空间”键。现在,我想进一步开发它。当它进入“如果”期间时,它将发送信号并开始自动播放视频。

greetings to each of you. I need your help. I am working on a project. I need that when a > is greater than 5, the arduino sends a signal to the computer and starts playing the video on the computer. my computer operation system is Windows11. I want play video on windows media player or anything. everytime my computer is open and video on media player ready to play. I don't know how to do it. first I connected the servo motor, the servo motor rotated 70 degrees and hit the computer's "space" key. now I want to develop it further. When it enters the "if" period, it will send a signal and start playing the video automatically.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡水深流 2025-02-10 20:17:35

您不需要如此复杂。使用Java,C#或Python,您可以编码脚本,在其中可以读取值并在串行端口上采取操作。对于Arduino侧用途serial.begin(9600);setup()中,然后在loop as中写入您的代码:

while (a > 5 )
{
    Serial.println(1);
}

当您的大于5,我们将1值发送到串行端口。现在,我将继续解释Python。

import serial
ser = serial.Serial('COM5')
ser.flushInput()

while True:
    try:
        ser_bytes = ser.readline()
        decoded_bytes = float(ser_bytes[0:len(ser_bytes)-2].decode("utf-8"))
        print(decoded_bytes)
    except:
        print("Keyboard Interrupt")
        break

您进行测试并在中写代码部分。

You don't need to think so complicated. With Java, C# or Python, you can code scripts where you can read values and take actions over the serial port. For Arduino side use Serial.begin(9600); in the setup() and write your code in loop as:

while (a > 5 )
{
    Serial.println(1);
}

While your a greater than 5 we send 1 value to serial port. Now I will continue to explain over python.

import serial
ser = serial.Serial('COM5')
ser.flushInput()

while True:
    try:
        ser_bytes = ser.readline()
        decoded_bytes = float(ser_bytes[0:len(ser_bytes)-2].decode("utf-8"))
        print(decoded_bytes)
    except:
        print("Keyboard Interrupt")
        break

You do your test and write your code in try section.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文