Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

how to take multiple inputs from keypad

Status
Not open for further replies.

farhan92

New Member
how to take multiple inputs from keypad using inkey command??
i want to make security system , for which i hav to take multiple inputs ,
 
how to take multiple inputs from keypad using inkey command??
i want to make security system , for which i hav to take multiple inputs ,

You mean you want to read a keypad in one go?...... You need to write a function to return the input from a 4x4 or 4x3 matrix?
 
yes ian, i want to read a keypad in one go,

main:
Cls
Print $FE,$C0,"enter password"
DelayMS 30
GoSub key1
DelayMS 500
GoSub key2
DelayMS 500
GoSub key3
DelayMS 500
Cls
GoSub diplay:
DelayMS 1000
GoTo main
key1:
countKey = InKey
DelayMS 20
If countKey<>16 Then
Select countKey
Case 0: key=1
Case 1: key=6
Case 2: key=7
Case 4: key=2
Case 5: key=5
Case 6: key=8
Case 8: key=3
Case 9: key=4
Case 7: key=0
Case 10: key=9

End Select
Else GoTo key1
EndIf

numnew=key
numstore=numnew
Return

key2:
countKey1 = InKey
DelayMS 20
If countKey1<>16 Then
Select countKey1
Case 0: key11=1
Case 1: key11=6
Case 2: key11=7
Case 4: key11=2
Case 5: key11=5
Case 6: key11=8
Case 8: key11=3
Case 9: key11=4
Case 7: key11=0
Case 10: key11=9

End Select
Else GoTo key2
EndIf

numnew1=key11
numstore1=numnew1
Return
key3:
countKey2= InKey
DelayMS 20
If countKey2<>16 Then
Select countKey2
Case 0: key22=1
Case 1: key22=6
Case 2: key22=7
Case 4: key22=2
Case 5: key22=5
Case 6: key22=8
Case 8: key22=3
Case 9: key22=4
Case 7: key22=0
Case 10: key22=9

End Select
Else GoTo key3
EndIf

numnew2=key22
numstore2=numnew2
Return
diplay:
If numstore=1 Then
If numstore1=2 Then
If numstore2=3 Then
Print At 1,1 ,"correct pasword"

Toggle PORTC.2
Else
Print At 1,1 ,"incorrect"
Print At 2,1 ," pasword"
EndIf
EndIf
EndIf
Return
can i use string ??or aray , as it become too lenghty
 
Code:
main:
	Cls
	Print $FE,$C0,"enter password"
	DelayMS 30
	GoSub key1
	DelayMS 500
	GoSub key2
	DelayMS 500
	GoSub key3
	DelayMS 500
	Cls
	GoSub diplay:
	DelayMS 1000
	GoTo main
key1:
	countKey = InKey 
	DelayMS 20
	If countKey<>16 Then
		Select countKey
			Case 0: key=1
			Case 1: key=6
			Case 2: key=7
			Case 4: key=2
			Case 5: key=5
			Case 6: key=8
			Case 8: key=3
			Case 9: key=4
			Case 7: key=0
			Case 10: key=9
		End Select
	Else 
		GoTo key1
	EndIf

	numnew=key
	numstore=numnew
	Return
key2:
	countKey1 = InKey 
	DelayMS 20
	If countKey1<>16 Then
		Select countKey1
			Case 0: key11=1
			Case 1: key11=6
			Case 2: key11=7
			Case 4: key11=2
			Case 5: key11=5
			Case 6: key11=8
			Case 8: key11=3
			Case 9: key11=4
			Case 7: key11=0
			Case 10: key11=9
		End Select
	Else 
		GoTo key2
	EndIf
	numnew1=key11
	numstore1=numnew1
	Return
key3:
	countKey2= InKey 
	DelayMS 20
	If countKey2<>16 Then
		Select countKey2
			Case 0: key22=1
			Case 1: key22=6
			Case 2: key22=7
			Case 4: key22=2
			Case 5: key22=5
			Case 6: key22=8
			Case 8: key22=3
			Case 9: key22=4
			Case 7: key22=0
			Case 10: key22=9
		End Select
	Else 
		GoTo key3
	EndIf
	numnew2=key22
	numstore2=numnew2
	Return
diplay:
	If numstore=1 Then
		If numstore1=2 Then
			If numstore2=3 Then
				Print At 1,1 ,"correct pasword"

				Toggle PORTC.2
				Else
				Print At 1,1 ,"incorrect"
				Print At 2,1 ," pasword"
			EndIf
		EndIf
	EndIf
	Return

Its easier to read when you use the code tags.... What system is this on? How many keys are there?

Is this Basic Stamp
 
Ok... its easier to read a keypad in a loop and return a lookup value

This is my 3x4 keypad function:--

Code:
function getkey() as byte
   dim keymask as byte
   dim key as byte
   dim index as byte
	keymask = 0xef
	For index = 0 To 3
		PORTB = keymask
		WaitUs 100
		key = PORTB And 0xf
		If key = 0xf Then key = 0
		If key = 0xe Then key = 1
		If key = 0xd Then key = 2
		If key = 0xb Then key = 3
		If key = 0x7 Then key = 4
		If key > 0 Then
			key = key + (index * 4)
			Gosub beep
			getkey = LookUp(0, 6, 7, 8, 9, 5, 11, 12, 10, 1, 2, 3, 4), key
			Goto finkey
			Endif
		keymask = ShiftLeft(keymask, 1)
	Next index
	getkey = 0
finkey:
end function

I use a sub routine beep 200ms sound 200ms no sound ( noise for user and plenty debounce..)
 
Last edited:
thanks alot IAN, i did another thing usng inkey command , i also make a sub routine to take 3 values from user
Code:
Dim mouse As 2
Dim countKey As Byte
Dim key As Byte
Dim numstore[3] As Byte
Dim aloop As Byte
main:
Cls
DelayMS 30
Print At 1,1,"enter num"
DelayMS 500
GoSub x1
p:
DelayMS 100
Cls 
Print At 1,1,Str numstore
DelayMS 1000
GoTo main


  x1:
   For aloop=0 To mouse Step 1
  DelayMS 100
  Cls
  Print "press key"
  x2:
  DelayMS 50
  countKey=InKey
    If countKey<>16 Then
        Select countKey
            Case 0: key="1"
            Case 1: key="6"
            Case 2: key="7"
            Case 4: key="2"
            Case 5: key="5"
            Case 6: key="8"
            Case 8: key="3"
            Case 9: key="4"
            Case 7: key="0"
            Case 10: key="9"
            Case 12: key="a"
            Case 13: key="b"
        End Select
        Else 
     GoSub x2
    EndIf
    numnew=key
    numstore[aloop]=numnew
    DelayMS 30
    Next
   
    GoTo p
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top