oButton Object

Main Index
Object List
Back to top of pageDescription:
 

A Hardware Object that reads the state of a switch and controls the state of an LED using a single I/O line.  The switch can be configured as a push button or a toggle button and the LED can be set to steady on, steady off or 3 different patterns of blinking.

 The following table lists the size and availability of the oButton Object.
 ObjectSizeDescriptionA1A2B1B2C1
oButton3 BytesReads the position of a switch and controls an LED light.xx
Back to top of pageOperation:
 An oButton Object continuously cycles between controlling one of two different objects each of which share a single I/O line.  The first functions as a digital Input which reads a push-button style switch and the second functions as a digital output which controls an LED.  In order for both the LED and the push button to be connected to the same I/O line, they Must be connected to the I/O line through a resister as indicated by the wiring diagram in the Connection section.

In the first half of the cycle, when operating as a digital Input, the oDIO1RW Object (DIO property) is used to read the position of a switch.  The Position property is set depending on the combination of the state of the switch and the Mode property. 

If the Mode property is set to 0, then the push button is treated as a regular push button where pressed is on, and released is off.  If the Mode property is 1, then the push button is treated as a toggle switch where pressed once is on and pressed a second time is off. 

In both modes, changing from off to on or on to off sets the Position property accordingly.  Note that the Position property is only modified when the push button physically changed state.  This allows the application program to preset the Position property or to change it after it has been set by the user's interaction.

In the second half of the cycle, when the oButton is operating as a digital Output, the oLEDB Object (LED property) is used to control an LED.  the Position property is used to specify whether or not the LED is on or off.  If 1, then the LED is turned on and if 0, then the LED is turned off.  Some of the properties of the oLED Object can be changed without interfering with the oButton's control.  For instance, the LED.Blink property changes the appearance of the LED when it is on.  If LED.Blink is set to 0, then the LED glows continuously.  However, LED.Blink is 1 or more, then the LED blinks in various ways.  (See the oLEDB Object for more detail)

In normal operation, the Position property controls the state of the LED. By setting the Option property to 1, this control can be turned off.  Note that when the Position property is in control, the oLEDB Object's Operate property is over-ridden by the oButton's Position property and therefore has no effect.  However, by setting the Option property to 1, the oLEDB Object's Operate property regains control.

Back to top of pageProperties:

The following table lists the properties of the oButton Object:

Property

Description

Position
A value that indicates the position of the button.
Object Class: oLogic Value Range: 0 - 1
Data Type: Numeric Default Value: 0
PositionConstantDescription
0cvOffThe button state is off.
1cvOnThe button state is on.
IsOn
A value that indicates if the button is in the ON position.
Object Class: oProperty Value Range: 0 - 1
Data Type: Numeric (Read-Only) Default Value: 0
IsOff
A value that indicates if the button is in the OFF position.
Object Class: oProperty Value Range: 0 - 1
Data Type: Numeric (Read-Only) Default Value: 0
IOLine
A value that specifies which I/O Line is connected to the switch and the LED.
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.
Mode
A value that selects if the button is treated as a push-button or a toggle-switch.
Object Class: oSelect0to1 Value Range: 0 - 1
Data Type: Numeric Default Value: 0
ModeDescription
0The button is treated as a push button.  Pressed is on, Released is off.
1The button is treated as a toggle switch, Pressed once is on, Pressed second time is off.
Option
A value that selects if the LED is set on or off based on the Position property.
Object Class: oSelect0to1 Value Range: 0 - 1
Data Type: Numeric Default Value: 0
OptionDescription
0The LED is controlled by the Position property.
1The LED is controlled by the LED.Operate property.
DIO
The I/O function object used to read the Button.
Object Class: oDIO1RW Value Range: 0 - 1
Data Type: Numeric Default Value: 0
LED
The LED object used to control the LED.
Object Class: oLEDB 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 pageExamples:
 In the following example, the oButton Object is used to read a switch and control and LED on I/O line 7.  When the button position is 1, a speaker will produce a tone.  The button is set to toggle mode, so one press turns the LED and the speaker on and a second press turns the speaker off.
Dim A As New oButton
Dim B As New oSpeaker

Sub Main()
  A.IOLine = 7
  A.Mode = 1
  B.Tone = 40000
  Do
    B.Operate = A.Position
  Loop
End Sub
Back to top of pageConnections:
The actual values of the two resistors are based on the power requirements of the LED that is used in the circuit. Note that both resistors need to be the same value.

Back to top of page Related Items:

 The following table lists objects with related functions
 ObjectDescriptionA1A2B1B2C1
oSwitchReads the position of a switch.xxxxx
oKeypadReads a 4 x 4 Keypad matrix.xxxxx
Back to top of page Version History and Bug List:
 Firmware Ver B2: Introduced.

Bugs: No known bugs.


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