oSwitch Object

Back to top of page Description:
 An oSwitch Object is a Hardware Object that uses a single digital I/O lines to monitor the position of the switch.
 The following table lists the size and availability of the oSwitch Object.
 ObjectSizeDescriptionA1A2B1B2C1
oSwitch1Reads the position of a switch.xxxxx
Back to top of page Operation:
 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.

Back to top of page Properties:

The following table lists the properties of the oSwitch Object:

Property

Description

Position
A value that indicates the position of the switch.
Object Class: oLogic Value Range: 0 - 1
Data Type: Numeric Default Value:

n/a

PositionBrake Output
0Switch is in the off position.
1Switch is in the on position.
IOLine
A value that specifies which I/O line is connected to the switch.
Object Class: oIOLine Value Range: 0 - 31
Data Type: Numeric Default Value: 0
Some I/O Lines have special purposes.  Be sure to see oIOLine help file for details.
IsOn
A value that indicates if the switch is in the ON position.
Object Class: oProperty Value Range: 0 - 1
Data Type: Numeric (Read-Only) Default Value:

n/a

The IsOn property reports the same value as the Position property.  It is worded to be understood in an evaluation such as: if X.IsOn then...
IsOnDescription
0Switch is in the off position.
1Switch is in the on position.
IsOff
A value that indicates if the switch is in the OFF position.
Object Class: oProperty Value Range: 0 - 1
Data Type: Numeric (Read-Only) Default Value:

n/a

The IsOff property reports the reverse value as the Position property.  It is worded to be understood in an evaluation such as: if X.IsOff then...
IsOnDescription
0Switch is in the on position.
1Switch is in the off position.
DIO
The I/O function object used to read the switch.
Object Class: oDIO1 Value Range: 0 - 1
Data Type: Numeric Default Value: 0
Address
Returns a pointer to the address of the oCounter Object instance.
Object Class: oAddress Value Range: 0 - 127
Data Type:Pointer (Read Only) Default Value: Address of Object

Back to top of page Example:

The following examples use the oSwitch Object.
Visual Basic SyntaxC and Java Syntax
'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
 
Back to top of pageConnections:
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.

Back to top of page Related Items:

 The following table lists objects with related functions
 ObjectDescriptionA1A2B1B2C1
oButtonReads the position of a switch and controls an LED light.xx
Back to top of page Version History and Bug List:
 Firmware Ver A1: Introduced.

Bugs: No known bugs.


ooPIC Compiler Ver 6.0 (c) Copyright 1997 - 2007 Savage Innovations, LLC.