Program LED with just USB port

2019-04-08 19:56发布

I want to control LED with C# using only USB port. I don't want to attach any other device with USB. I just want to attach LED directly to USB port pins and program it (blink etc). How can i do that? I am new to hardware programming and it will be my first program.

EDIT: I can do it already (blink LED) using printer port by attaching one led pin to data pin and other to ground. How can i do the same with USB port? My motherboard does not have a printer port. USB is the only option.

6条回答
够拽才男人
2楼-- · 2019-04-08 20:12

I can do it already (blink LED) using printer port...

OK, so why not buy a cheap USB based printer port and use that? Since you already have the LPT port code working, this gives you a transparent solution.

查看更多
Bombasti
3楼-- · 2019-04-08 20:18

This is not possible.

4 usb pins

| | | |  
| | | |  
1 2 3 4

1: +5V
2: D-
3: D+
4: Ground

To trun on LED connect with 1 and 4

Current on Data pins is too low therefore LED will never turn on if connected with 5V and any Data pin. Hence LED can not be controlled directly using data pins on USB port

查看更多
虎瘦雄心在
4楼-- · 2019-04-08 20:19

If you can clear the motive of controlling LED using USB then it will be very helpful to answer the Q:

查看更多
smile是对你的礼貌
5楼-- · 2019-04-08 20:22

Many mainboards will permanently supply USB ports with current.

You could theoretically put the USB controller into some suspend mode and back again but this is bad.

You'd need some sort of controller to accept commands over USB then some discrete elements to open/close current from the permanent USB supply and let it reach your LED.

查看更多
小情绪 Triste *
6楼-- · 2019-04-08 20:23

You really can't do this. You can do it with a parallel port because you have individual control over the data pins. With USB, you only have control over the data the rides on top of the USB protocol. It's likely that protocol is being run in firmware by a chip on the motherboard anyway, so there's most likely no way to do what you want to do, short connecting the LED across the power pins and toggling the USB bus power, which you should NOT do for a whole variety of reasons.

Just get an Arduino or something. In the long run it will be a lot easier and be more flexible.

查看更多
迷人小祖宗
7楼-- · 2019-04-08 20:24

You could use a PIC microcontroller . The 18f series can directly interface led's over the usb . It is also possible to code using c# and use only the USB port to control the led . I'm guessing you actually want to control the led and not just get it to glow .

查看更多
登录 后发表回答