打开和关闭Leds [英] Turn on and off Leds

查看:79
本文介绍了打开和关闭Leds的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何通过USB端口发送信息。

我的项目:我想设计一个程序,使用USB端口打开LED(因为我正在使用笔记本电脑)

我有代码使其成为串口,但它对我没用。



感谢您的帮助。

I'd like to know how to send info through the usb port.
My project: I want to design a program that turns on leds using the usb port (because I'm using a laptop)
I have the code to make it uisng the serial port, but it's not useful for me.

Thanks for helping.

推荐答案

好的,我会扩展关于ThePhantomUpvoter的消息,主要是因为我涉足嵌入式电子产品......



串口工作是通过高或低信号来实现的。有一些像DTR和RTS这样的信号可以通过代码轻松控制,并保持高或低。 RX和TX引脚通常不是这种情况,因为它们在特定时刻非常快速地从高电平变为低电平,以便将位发送到另一端。 DTR和RTS在那里通知另一端它准备发送或准备接收。基本上,RS-232使用9个引脚,DTR,RTS,DCD,CTS,DSR,RI,RX,TX和GND。 GND(接地)是恒定的,与计算机电源共用。 RX和TX在特定时间循环以发送和接收数据。 DTR,RTS,DCD,DSR和CTS是控制引脚,可以驱动保持特定值。



USB是一个完全不同于电子方面的系统。有4个引脚,+ 5V,GND,D +和D-。显然+ 5V和GND用于供电,但D +和D-有点像RX和TX引脚,除了它们的工作方式不同。您无法使用它们打开或关闭LED,因为您无法将它们驱动到特定状态并将其保持在那里。



如果你想开车LED,看看连接Arduino,或者获得USB转串口转换器并按照这种方式进行。
Alright, I'll expand on ThePhantomUpvoter's message, mostly because I dabble in embedded electronics...

Serial ports work by bringing a signal high or low. There are a couple signals like DTR and RTS that can be easily controlled through code, and made to stay high or low. These aren't typically the case with the RX and TX pins because they go high to low very quickly at a specific timing to send bits to the other end. DTR and RTS are there to notify the other end that its ready to send or ready to receive. Basically there are 9 pins that RS-232 uses, DTR, RTS, DCD, CTS, DSR, RI, RX, TX and GND. GND (Ground) is constant and shared with the computer power supply. RX and TX cycle at a specific timing for sending and receiving data. DTR, RTS, DCD, DSR, and CTS are control pins that can be driven to stay at a specific value.

USB is a completely different system from the electronics side. There are 4 pins, +5V, GND, D+ and D-. Obviously +5V and GND are used for power, but D+ and D- are kind of like the RX and TX pins, except they work differently. You can't use them to turn an LED on or off because you can't drive them to a specific state and hold them there.

If you want to drive LED's, take a look at interfacing the Arduino, or get a USB to Serial converter and do it that way.


在我看来,你应该使用微控制器来切换 ON / OFF LED (或控制其他硬件)。反过来,您的笔记本电脑将与微控制器通信(直接通过 USB 或通过虚拟 COM USB )。

直接连接 LED (或其他硬件)可能(如果错误) )对您的笔记本电脑造成伤害并且难以在软件中处理。)
In my opinion, you should use a microcontroller to switch ON/OFF the LEDs (or control other hardware). In turn your laptop would communicate with the microcontroller (directly via USB or by means of a virtual COM on the USB).
The direct connection of the LEDs (or other hardware) may (if wrong) phisically harm your laptop and it is difficult to handle in software).


根据您的预算(对于快速个人项目而言,它们并不便宜)您也可以使用 XBee模块 [ ^ ]这样做。其中一个有一个USB(在我得到的集合中),然后你可以无线地进行。



老实说,很难回答这个问题。完整的方式,但不知道你正在使用的硬件。



编辑:意识到我链接的页面只有无线模块的信息,其中的USB适配器 [ ^ ]
Depending on your budget (they aren't exactly cheap for a quick personal project) you could also use XBee modules[^] to do this. One of them has a USB in (in the set I got), and then you can do it wirelessly.

Honestly, it's pretty hard to answer this question in a complete way without knowing the hardware you're using though.

realized the page I linked just had information about the wireless modules, here's the USB adapter[^]


这篇关于打开和关闭Leds的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆