The oSwitch Object monitors the I/O line specified by the IOLine property and based on the electrical state of the I/O line, sets the value of the Position property.
When the electrical state is 0 Volts, the Position property is set to 0 and if the Electrical state is 5 Volts, the Position Property is set to 1.
The Position property is an instance of the oLogic Object and therefore can be pointed to by a virtual circuit.
'This program creates changes
'the brightness of an led
'when a switch is closed.
Dim Fred As New oSwitch
Dim Bob As New oLED
Sub Main()
Bob.IOLine = 8
Fred.IOLine = 9
Do
If Fred.IsOn Then
Bob.TurnOnBright
Else
Bob.TurnOnDim
EndIf
Loop
End Sub
//This program creates changes
//the brightness of an led
//when a switch is closed.
oSwitch Fred = New oSwitch;
oLED Bob = New oLED;
Void Main(Void){
Bob.IOLine = 8;
Fred.IOLine = 9;
Do{
If (Fred.IsOn){
Bob.TurnOnBright;
} Else {
Bob.TurnOnDim;
}
} While (1);
}
Basic Syntax
'This program creates changes
'the brightness of an led
'when a switch is closed.
Fred As oSwitch(9)
Bob As oLED(8)
Do
If Fred.IsOn Then
Bob.TurnOnBright
Else
Bob.TurnOnDim
EndIf
Loop
The oSwitch uses one I/O line. This I/O line is connected to one of the terminals of the switch and through a resistor to ground. The resistor is 1k ohms and cause the I/O line to be at 0 Volts unless the switch is creating a connection between the I/O Line and 5 Volts. Most any switch can be used. Shown is a toggle switch, push button switch, slide switch and a magnetic reed switch.