Re: Need to add a push button to my computer (no parellel po
hi,
you can use the serial port " data carrier detect " pin 1 of 9.
the switch should toggle between GND and VCC.
1. Start a new instance of Visual Basic.
2. Create a new Standard EXE project. Form1 is created by default.
3. Choose Components from the Project menu, check the "Microsoft Comm Control," and click OK.
4. Add an MSCOMM control to the form.
6. Add the following code to Form1's code window:
Private Sub Form_Load()
Form1.Caption = "App2"
With MSComm1
.CommPort = 2
.Handshaking = 2 - comRTS
.RThreshold = 1
.RTSEnable = True
.Settings = "9600,n,8,1"
.SThreshold = 1
.PortOpen = True
' Leave all other settings as default values.
End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
MSComm1.PortOpen = False
End Sub
Private Sub MSComm1_OnComm()
if MSComm1.CommEvent=comEvDSR then
msgbox "button pressed"
end if
end sub
You can develop a small microcontroller based product which will talk to PC over RS-232 port. You can connect switches to microcontroller's input ports and write a software to communicate there status to the PC.
Actully it will be little expensive solution but you can do lot of other things using the same circuit like adding LCD Display etc.
You don't need a SPDT (3 contact) switch. A SPST (2 contact) switch will do just fine. Connect one side of the switch to ground. Connect the other side to the serial port pin AND to a resistor (2 K will do). Connect the other side of the resistor to Vcc.
You can actually use other pins on the serial port for power. If you set RTS high, you can use that pin for +12. Generally ground is ok for the low signal, but if not set one of the serial control signals to -12 and use that pin.
I don't mind putting a resistor on a single one.. but might be doing many of these.. So if I use a 3 contact (SPDT), will I have to use a contact ? I am guessing, yes oneither.. but just checking..
thanks!
Re: Need to add a push button to my computer (no parellel po
I don't quite understand your question.
If you use a spdt (3 contact) you will have to connect 3 wires (no resistor).
If you use a spst (2 contact) you will have to connect 2 wire (one with a resistor in series).
you need to connect the Com to pin 1 of 9 (carier detect)
you need to connect the L1 to pin 5 of 9 (Ground)
you need to connect the L2 to pin 7 of 9 (will used as VCC)
in order to use pin 7 as VCC you will need to add the next line:
mscomm1 .RTSEnable=true
at stady state the com is conncted to the L1-GND (pin 5) . when you press the switch the com is connected to L2-VCC(pin 7). then the visual basic will recognize change and will go to the function.