![]() |
Connecting Switches to Digital I/O Lines To connect switches to digital I/O lines, only one additional
component is required. Each digital input line used to read a switch must be tied to +5
volts with a 10Kohm resistor to avoid leaving the digital port floating when the switch is
in the OPEN position. The switch is then connected between ground and the digital port.
The program used to read the switches must first configure the digital I/O lines as input.
This is done using the CPAxxxxxxxx command. To read the switch a RPAx command is used. The
following BASIC program continually monitors the position of two switches using an ADR101 and updates their status on the screen. 10 OPEN "COM1:9600,N,8,1,CS,DS,RS" AS#1 20 CLS 30 PRINT#1, "CPA11111111" 40 REM (FORCES CR) 50 PRINT#1, "RPA0" 60 INPUT#1, SWA 70 T1$="CLOSED" IF SWA=1 THEN T1$="OPEN" 80 PRINT#1, "RPA1" 90 INPUT#1, SWB 100 T2$="CLOSED" IF SWB=1 THEN T2$="OPEN" 110 LOCATE 1,1 120 PRINT "SWITCH A IS "T1$ 130 PRINT "SWITCH B IS "T2$ 140 GOTO 50 |
|