oKeypad2 Object

Back to top of page Description:
 

The oKeypad2 Object is a Hardware Object that scans a matrix of switches up to 8 x 8 in size and determines which switch is pressed.

The number of columns and number of rows are selectable, both up to 8 switches. 

 The following table lists the size and availability of the oKeypad2 Object.
 ObjectSizeDescriptionA1A2B1B2C1
oKeypad26 BytesReads a Keypad matrix of up to 8 x 8.xx
Back to top of page Operation:
 An oKeypad2 Object scans the I/O lines in I/O Group 1 (I/O lines 8 - 15) and the I/O lines in I/O group 3 for switched connections between the group's I/O lines. 

The set of I/O lines in I/O Group 1 are used for the keypad's 8 columns and the I/O lines in I/O group 3 are used for the keypad's 8 rows. 

Both the row and the column I/O groups have a mask that allows specific I/O lines within the groups to be selected for use.  This option allows the keypad matrix to be any combination of rows and columns up to 8 by 8.  As an example, if only 5 I/O lines are selected for the row and 4 bits are selected for the column, then the resulting scan pattern would scan a 5 by 4 keypad matrix which would contain 20 switches.

If the total number of rows and columns is 8 or less as in the case of a 3 by 5 keypad, then the

When the Operate property is set to 1 the keypad switch matrix is scanned for a switch-press.  If any switch is pressed, the Key property is updated with the value of the switch and the Pressed property is set to 1.  The value of the switch is calculated by (((Row - 1) * 8) + (Column-1)).  If two switches are pressed simultaneously the switch with the highest value will be used.

The Pressed property will remain at 1 so long as at least 1 switch is depressed.  If a second key is pressed before the originally pressed key is released, the Value and Pressed property will remain unchanged from the values set at the time of the depression of the first key. Once all keys are released, the Pressed property will be cleared to 0.

When the Operate property is set to 0 the switch matrix scanning is suspended until the Operate property is set back to 1.

The FeedBack property is an instance of the oFeedBack8 Object which is created when the oKeypad2 object is.  The oKeypad2 object uses the oFeedBack8 Object to do the actual scanning of the keypad.  (see oFeedBack8 Object for more detail on how the keypad is scanned.)

Back to top of page Properties:

The following table lists the properties of the oKeypad2 Object:

Property

Description

Key
A value that indicates the switch number of the last switch that was pressed.
Object Class: oByte Value Range: 0 - 15
Data Type: Numeric (Read-Only) Default Value: 0
Key = (((Row - 1) * 8) + (Column-1)).
Pressed
A value that indicates that a new key has been pressed.
Object Class: oLogic Value Range: 0 - 1
Data Type: Numeric Default Value: 0
PressedDescription
0No key is pressed.
1Any one or more keys are pressed.
ColMask
A value that specifies which I/O lines from I/O Group 1 to use for the keypad's columns.
Object Class: oVar8 Value Range: 0 - 255
Data Type: Numeric Default Value: 0
For each bit set in the mask, the corresponding bit of the group will be used.
RowMask
A value that specifies which I/O lines from I/O Group 3 to use for the keypad's rows.
Object Class: oVar8 Value Range: 0 - 255
Data Type: Numeric Default Value: 0
For each bit set in the mask, the corresponding bit of the group will be used.
IOGroup
I/O Group used for the Row connections.
Object Class: oIOGroup Value Range: 0 - 3
Data Type: Numeric Default Value: 3
IOGroupRDescription
0Group 1 is used.
1
2Group 3 is used.
3
Operate
A value that selects whether or not the keypad is being read.
Object Class: oOperate Value Range: 0 - 1
Data Type: Numeric Default Value: 0
OperateConstantDescription
0cvOff

The keypad is not being read.

1cvOn

The keypad is being read.

FeedBack
The I/O function object used to read the keypad.
Object Class: oFeedBack8 Value Range: 0 - 255
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 Examples:
 In the following example, the oKeypad2 Object is used to set the value of a oByte Object to the number of the pressed switch.
' This program reads an oKeypad2 Object
' set up to read a 4x4 keypad using 
' the 8 I/O Lines in I/O Group 1 and 
' outputs the value to I/O Group 3.

Dim A As New oKeypad2
Dim C As New oDio8

Sub Main() 
  ooPIC.Node = 5
  A.RowMask = &B11110000
  A.ColMask = &B00001111
  A.Operate = 1 
  A.IOGroupC = 1
  C.IOGroup = 3
  C.Direction = cvOutput
  Do
    B.Value = A.Key
  Loop
End Sub
'This program reads a 3x5 keypad from Radio 
'Shack using the 8 I/O Lines in I/O Group 1
'and outputs the value to I/O lines 24- 31.

Dim A As New oKeypad2
Dim D As New oDio1
Dim C As New oDio8 

Sub Main() 
  C.IOGroup = 3
  C.Direction = cvOutput
  D.IOLine = 7
  D.Direction = cvOutput
  A.RowMask = &B11010011
  A.ColMask = &B00101100
  A.IOGroupC = 1
  A.Operate = 1
  Do
    C = A.Key
    D = A.Pressed 
  Loop
end sub
Back to top of pageConnections:
 The keypad switch matrix requires no isolation diodes or pull up resistors for operation since the IOLines 8-15 already have internal pull-ups on them.  Connect the 8 wires of IOGroup 1 to the column connection of C1 to C8.   and the wires of IOGroup 3 to R1 to R8.  Or, if a mask is applied, the ones specified by the mask.

Schematic of the keypad

Back to top of page Related Items:

 The following table lists objects with related functions
 ObjectDescriptionA1A2B1B2C1
oKeypadReads a 4 x 4 Keypad matrix.xxxxx
oKeypadPReads a Telephone Keypad.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.